home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / PL 2.0 SupplementDoc Folder.sit / PL 2.0 SupplementDoc Folder / Documentation / Chapter 28. CLOS < prev    next >
Text File  |  1996-05-27  |  231KB  |  5,001 lines

  1. Common Lisp the Language, 2nd Edition
  2. -------------------------------------------------------------------------------
  3.  
  4. 28. Common Lisp Object System
  5.  
  6. By Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene,
  7. Gregor Kiczales, and David A. Moon
  8.  
  9. [change_begin]
  10. PREFACE: X3J13 voted in June 1988 (CLOS)   to adopt the first two chapters (of
  11. three) of the Common Lisp Object System specification as a part of the
  12. forthcoming draft Common Lisp standard.
  13.  
  14. This chapter presents the bulk of the first two chapters of the Common Lisp
  15. Object System specification; it is substantially identical to these two
  16. specification chapters as previously published elsewhere [5,6,7]. I have edited
  17. the material only very lightly to conform to the overall style of this book and
  18. to save a substantial number of pages by using a typographically condensed
  19. presentation. I have inserted a small number of bracketed remarks, identified
  20. by the initials GLS. The chapter divisions of the original specification have
  21. become section divisions in this chapter; references to the three chapters of
  22. the original specification now refer to the three ``parts'' of the
  23. specification. (See the Acknowledgments to this second edition for
  24. acknowledgments to others who contributed to the Common Lisp Object System
  25. specification.) This is not the last word on CLOS; X3J13 may well refine this
  26. material further. Keene has written a good tutorial introduction to CLOS [26].
  27.  
  28.      - Guy L. Steele Jr.
  29.  
  30. [change_end]
  31. -------------------------------------------------------------------------------
  32.  
  33.    *  Programmer Interface Concepts
  34.         o  Error Terminology
  35.         o  Classes
  36.              +  Defining Classes
  37.              +  Creating Instances of Classes
  38.              +  Slots
  39.              +  Accessing Slots
  40.         o  Inheritance
  41.              +  Inheritance of Methods
  42.              +  Inheritance of Slots and Slot Options
  43.              +  Inheritance of Class Options
  44.              +  Examples
  45.         o  Integrating Types and Classes
  46.         o  Determining the Class Precedence List
  47.              +  Topological Sorting
  48.              +  Examples
  49.         o  Generic Functions and Methods
  50.              +  Introduction to Generic Functions
  51.              +  Introduction to Methods
  52.              +  Agreement on Parameter Specializers and Qualifiers
  53.              +  Congruent Lambda-Lists for All Methods of a Generic Function
  54.              +  Keyword Arguments in Generic Functions and Methods
  55.         o  Method Selection and Combination
  56.              +  Determining the Effective Method
  57.              +  Standard Method Combination
  58.              +  Declarative Method Combination
  59.              +  Built-in Method Combination Types
  60.         o  Meta-objects
  61.              +  Metaclasses
  62.              +  Standard Metaclasses
  63.              +  Standard Meta-objects
  64.         o  Object Creation and Initialization
  65.              +  Initialization Arguments
  66.              +  Declaring the Validity of Initialization Arguments
  67.              +  Defaulting of Initialization Arguments
  68.              +  Rules for Initialization Arguments
  69.              +  Shared-Initialize
  70.              +  Initialize-Instance
  71.              +  Definitions of Make-Instance and Initialize-Instance
  72.         o  Redefining Classes
  73.              +  Modifying the Structure of Instances
  74.              +  Initializing Newly Added Local Slots
  75.              +  Customizing Class Redefinition
  76.              +  Extensions
  77.         o  Changing the Class of an Instance
  78.              +  Modifying the Structure of an Instance
  79.              +  Initializing Newly Added Local Slots
  80.              +  Customizing the Change of Class of an Instance
  81.         o  Reinitializing an Instance
  82.              +  Customizing Reinitialization
  83.    *  Functions in the Programmer Interface
  84.  
  85. -------------------------------------------------------------------------------
  86.  
  87. 28.1. Programmer Interface Concepts
  88.  
  89. [change_begin]
  90. The Common Lisp Object System (CLOS) is an object-oriented extension to Common
  91. Lisp. It is based on generic functions, multiple inheritance, declarative
  92. method combination, and a meta-object protocol.
  93.  
  94. The first two parts of this specification describe the standard Programmer
  95. Interface for the Common Lisp Object System. The first part, Programmer
  96. Interface Concepts, contains a description of the concepts of the Common Lisp
  97. Object System, and the second part, Functions in the Programmer Interface,
  98. contains a description of the functions and macros in the Common Lisp Object
  99. System Programmer Interface. The third part, The Common Lisp Object System
  100. Meta-Object Protocol, explains how the Common Lisp Object System can be
  101. customized. [The third part has not yet been approved by X3J13 for inclusion in
  102. the forthcoming Common Lisp standard and is not included in this book.-GLS]
  103.  
  104. The fundamental objects of the Common Lisp Object System are classes,
  105. instances, generic functions, and methods.
  106.  
  107. A class object determines the structure and behavior of a set of other objects,
  108. which are called its instances. Every Common Lisp object is an instance of a
  109. class. The class of an object determines the set of operations that can be
  110. performed on the object.
  111.  
  112. A generic function is a function whose behavior depends on the classes or
  113. identities of the arguments supplied to it. A generic function object contains
  114. a set of methods, a lambda-list, a method combination type, and other
  115. information. The methods define the class-specific behavior and operations of
  116. the generic function; a method is said to specialize a generic function. When
  117. invoked, a generic function executes a subset of its methods based on the
  118. classes of its arguments.
  119.  
  120. A generic function can be used in the same ways as an ordinary function in
  121. Common Lisp; in particular, a generic function can be used as an argument to
  122. funcall and apply and can be given a global or a local name.
  123.  
  124. A method is an object that contains a method function, a sequence of parameter
  125. specializers that specify when the given method is applicable, and a sequence
  126. of qualifiers that is used by the method combination facility to distinguish
  127. among methods. Each required formal parameter of each method has an associated
  128. parameter specializer, and the method will be invoked only on arguments that
  129. satisfy its parameter specializers.
  130.  
  131. The method combination facility controls the selection of methods, the order in
  132. which they are run, and the values that are returned by the generic function.
  133. The Common Lisp Object System offers a default method combination type and
  134. provides a facility for declaring new types of method combination.
  135. [change_end]
  136.  
  137. -------------------------------------------------------------------------------
  138.  
  139.    *  Error Terminology
  140.    *  Classes
  141.         o  Defining Classes
  142.         o  Creating Instances of Classes
  143.         o  Slots
  144.         o  Accessing Slots
  145.    *  Inheritance
  146.         o  Inheritance of Methods
  147.         o  Inheritance of Slots and Slot Options
  148.         o  Inheritance of Class Options
  149.         o  Examples
  150.    *  Integrating Types and Classes
  151.    *  Determining the Class Precedence List
  152.         o  Topological Sorting
  153.         o  Examples
  154.    *  Generic Functions and Methods
  155.         o  Introduction to Generic Functions
  156.         o  Introduction to Methods
  157.         o  Agreement on Parameter Specializers and Qualifiers
  158.         o  Congruent Lambda-Lists for All Methods of a Generic Function
  159.         o  Keyword Arguments in Generic Functions and Methods
  160.    *  Method Selection and Combination
  161.         o  Determining the Effective Method
  162.         o  Standard Method Combination
  163.         o  Declarative Method Combination
  164.         o  Built-in Method Combination Types
  165.    *  Meta-objects
  166.         o  Metaclasses
  167.         o  Standard Metaclasses
  168.         o  Standard Meta-objects
  169.    *  Object Creation and Initialization
  170.         o  Initialization Arguments
  171.         o  Declaring the Validity of Initialization Arguments
  172.         o  Defaulting of Initialization Arguments
  173.         o  Rules for Initialization Arguments
  174.         o  Shared-Initialize
  175.         o  Initialize-Instance
  176.         o  Definitions of Make-Instance and Initialize-Instance
  177.    *  Redefining Classes
  178.         o  Modifying the Structure of Instances
  179.         o  Initializing Newly Added Local Slots
  180.         o  Customizing Class Redefinition
  181.         o  Extensions
  182.    *  Changing the Class of an Instance
  183.         o  Modifying the Structure of an Instance
  184.         o  Initializing Newly Added Local Slots
  185.         o  Customizing the Change of Class of an Instance
  186.    *  Reinitializing an Instance
  187.         o  Customizing Reinitialization
  188.  
  189. -------------------------------------------------------------------------------
  190.  
  191. 28.1.1. Error Terminology
  192.  
  193. [change_begin]
  194. The terminology used in this chapter to describe erroneous situations differs
  195. from the terminology used in the first edition. The new terminology involves
  196. situations; a situation is the evaluation of an expression in some specific
  197. context. For example, a situation might be the invocation of a function on
  198. arguments that fail to satisfy some specified constraints.
  199.  
  200. In the specification of the Common Lisp Object System, the behavior of programs
  201. in all situations is described, and the options available to the implementor
  202. are defined. No implementation is allowed to extend the syntax or semantics of
  203. the Object System except as explicitly defined in the Object System
  204. specification. In particular, no implementation is allowed to extend the syntax
  205. of the Object System in such a way that ambiguity between the specified syntax
  206. of the Object System and those extensions is possible.
  207.  
  208. ``When situation S occurs, an error is signaled.''
  209.  
  210.      This terminology has the following meaning:
  211.  
  212.         o  If this situation occurs, an error will be signaled in the
  213.           interpreter and in code compiled under all compiler safety
  214.           optimization levels.
  215.  
  216.         o  Valid programs may rely on the fact that an error will be signaled
  217.           in the interpreter and in code compiled under all compiler safety
  218.           optimization levels.
  219.  
  220.         o  Every implementation is required to detect such an error in the
  221.           interpreter and in code compiled under all compiler safety
  222.           optimization levels.
  223.  
  224. ``When situation S occurs, an error should be signaled.''
  225.  
  226.      This terminology has the following meaning:
  227.  
  228.         o  If this situation occurs, an error will be signaled at least in the
  229.           interpreter and in code compiled under the safest compiler safety
  230.           optimization level.
  231.  
  232.         o  Valid programs may not rely on the fact that an error will be
  233.           signaled.
  234.  
  235.         o  Every implementation is required to detect such an error at least in
  236.           the interpreter and in code compiled under the safest compiler safety
  237.           optimization level.
  238.  
  239.         o  When an error is not signaled, the results are undefined (see
  240.           below).
  241.  
  242. ``When situation S occurs, the results are undefined.''
  243.  
  244.      This terminology has the following meaning:
  245.  
  246.         o  If this situation occurs, the results are unpredictable. The results
  247.           may range from harmless to fatal.
  248.  
  249.         o  Implementations are allowed to detect this situation and signal an
  250.           error, but no implementation is required to detect the situation.
  251.  
  252.         o  No valid program may depend on the effects of this situation, and
  253.           all valid programs are required to treat the effects of this
  254.           situation as unpredictable.
  255.  
  256. ``When situation S occurs, the results are unspecified.''
  257.  
  258.      This terminology has the following meaning:
  259.  
  260.         o  The effects of this situation are not specified in the Object
  261.           System, but the effects are harmless.
  262.  
  263.         o  Implementations are allowed to specify the effects of this
  264.           situation.
  265.  
  266.         o  No portable program can depend on the effects of this situation, and
  267.           all portable programs are required to treat the situation as
  268.           unpredictable but harmless.
  269.  
  270. ``The Common Lisp Object System may be extended to cover situation S.''
  271.  
  272.      The meaning of this terminology is that an implementation is free to treat
  273.      situation S in one of three ways:
  274.  
  275.         o  When situation S occurs, an error is signaled at least in the
  276.           interpreter and in code compiled under the safest compiler safety
  277.           optimization level.
  278.  
  279.         o  When situation S occurs, the results are undefined.
  280.  
  281.         o  When situation S occurs, the results are defined and specified.
  282.  
  283.      In addition, this terminology has the following meaning:
  284.  
  285.         o  No portable program can depend on the effects of this situation, and
  286.           all portable programs are required to treat the situation as
  287.           undefined.
  288.  
  289. ``Implementations are free to extend the syntax S.''
  290.  
  291.      This terminology has the following meaning:
  292.  
  293.         o  Implementations are allowed to define unambiguous extensions to
  294.           syntax S.
  295.  
  296.         o  No portable program can depend on this extension, and all portable
  297.           programs are required to treat the syntax as meaningless.
  298.  
  299. The Common Lisp Object System specification may disallow certain extensions
  300. while allowing others.
  301. [change_end]
  302.  
  303. -------------------------------------------------------------------------------
  304.  
  305. 28.1.2. Classes
  306.  
  307. [change_begin]
  308. A class is an object that determines the structure and behavior of a set of
  309. other objects, which are called its instances.
  310.  
  311. A class can inherit structure and behavior from other classes. A class whose
  312. definition refers to other classes for the purpose of inheriting from them is
  313. said to be a subclass of each of those classes. The classes that are designated
  314. for purposes of inheritance are said to be superclasses of the inheriting
  315. class.
  316.  
  317. A class can have a name. The function class-name takes a class object and
  318. returns its name. The name of an anonymous class is nil. A symbol can name a
  319. class. The function find-class takes a symbol and returns the class that the
  320. symbol names. A class has a proper name if the name is a symbol and if the name
  321. of the class names that class. That is, a class C has the proper name S if S =
  322. (class-name C) and C = (find-class S). Notice that it is possible for
  323. (find-class   ) = (find-class   ) and   . If C = (find-class S), we say that C
  324. is the class named S.
  325.  
  326. A class    is a direct superclass of a class    if    explicitly designates
  327. as a superclass in its definition. In this case,    is a direct subclass of   .
  328. A class    is a superclass of a class    if there exists a series of classes
  329. such that    is a direct superclass of    for 1 i < n. In this case,    is a
  330. subclass of   . A class is considered neither a superclass nor a subclass of
  331. itself. That is, if    is a superclass of   , then   . The set of classes
  332. consisting of some given class C along with all of its superclasses is called
  333. ``C and its superclasses.''
  334.  
  335. Each class has a class precedence list, which is a total ordering on the set of
  336. the given class and its superclasses. The total ordering is expressed as a list
  337. ordered from most specific to least specific. The class precedence list is used
  338. in several ways. In general, more specific classes can shadow, or override,
  339. features that would otherwise be inherited from less specific classes. The
  340. method selection and combination process uses the class precedence list to
  341. order methods from most specific to least specific.
  342.  
  343. When a class is defined, the order in which its direct superclasses are
  344. mentioned in the defining form is important. Each class has a local precedence
  345. order, which is a list consisting of the class followed by its direct
  346. superclasses in the order mentioned in the defining form.
  347.  
  348. A class precedence list is always consistent with the local precedence order of
  349. each class in the list. The classes in each local precedence order appear
  350. within the class precedence list in the same order. If the local precedence
  351. orders are inconsistent with each other, no class precedence list can be
  352. constructed, and an error is signaled. The class precedence list and its
  353. computation is discussed in section 28.1.5.
  354.  
  355. Classes are organized into a directed acyclic graph. There are two
  356. distinguished classes, named t and standard-object. The class named t has no
  357. superclasses. It is a superclass of every class except itself. The class named
  358. standard-object is an instance of the class standard-class and is a superclass
  359. of every class that is an instance of standard-class except itself.
  360.  
  361. There is a mapping from the Common Lisp Object System class space into the
  362. Common Lisp type space. Many of the standard Common Lisp types have a
  363. corresponding class that has the same name as the type. Some Common Lisp types
  364. do not have a corresponding class. The integration of the type and class
  365. systems is discussed in section 28.1.4.
  366.  
  367. Classes are represented by objects that are themselves instances of classes.
  368. The class of the class of an object is termed the metaclass of that object.
  369. When no misinterpretation is possible, the term metaclass will be used to refer
  370. to a class that has instances that are themselves classes. The metaclass
  371. determines the form of inheritance used by the classes that are its instances
  372. and the representation of the instances of those classes. The Common Lisp
  373. Object System provides a default metaclass, standard-class, that is appropriate
  374. for most programs. The meta-object protocol provides mechanisms for defining
  375. and using new metaclasses.
  376.  
  377. Except where otherwise specified, all classes mentioned in this chapter are
  378. instances of the class standard-class, all generic functions are instances of
  379. the class standard-generic-function, and all methods are instances of the class
  380. standard-method.
  381.  
  382. [change_end]
  383. -------------------------------------------------------------------------------
  384.  
  385.    *  Defining Classes
  386.    *  Creating Instances of Classes
  387.    *  Slots
  388.    *  Accessing Slots
  389.  
  390. -------------------------------------------------------------------------------
  391.  
  392. 28.1.2.1. Defining Classes
  393.  
  394. [change_begin]
  395. The macro defclass is used to define a new named class. The definition of a
  396. class includes the following:
  397.  
  398.    *  The name of the new class. For newly defined classes this is a proper
  399.      name.
  400.  
  401.    *  The list of the direct superclasses of the new class.
  402.  
  403.    *  A set of slot specifiers. Each slot specifier includes the name of the
  404.      slot and zero or more slot options. A slot option pertains only to a
  405.      single slot. If a class definition contains two slot specifiers with the
  406.      same name, an error is signaled.
  407.  
  408.    *  A set of class options. Each class option pertains to the class as a
  409.      whole.
  410.  
  411. The slot options and class options of the defclass form provide mechanisms for
  412. the following:
  413.  
  414.    *  Supplying a default initial value form for a given slot.
  415.  
  416.    *  Requesting that methods for generic functions be automatically generated
  417.      for reading or writing slots.
  418.  
  419.    *  Controlling whether a given slot is shared by instances of the class or
  420.      whether each instance of the class has its own slot.
  421.  
  422.    *  Supplying a set of initialization arguments and initialization argument
  423.      defaults to be used in instance creation.
  424.  
  425.    *  Indicating that the metaclass is to be other than the default.
  426.  
  427.    *  Indicating the expected type for the value stored in the slot.
  428.  
  429.    *  Indicating the documentation string for the slot.
  430.  
  431. [change_end]
  432.  
  433. -------------------------------------------------------------------------------
  434.  
  435. 28.1.2.2. Creating Instances of Classes
  436.  
  437. [change_begin]
  438. The generic function make-instance creates and returns a new instance of a
  439. class. The Object System provides several mechanisms for specifying how a new
  440. instance is to be initialized. For example, it is possible to specify the
  441. initial values for slots in newly created instances either by giving arguments
  442. to make-instance or by providing default initial values.
  443.  
  444. Further initialization activities can be performed by methods written for
  445. generic functions that are part of the initialization protocol. The complete
  446. initialization protocol is described in section 28.1.9.
  447. [change_end]
  448.  
  449. -------------------------------------------------------------------------------
  450.  
  451. 28.1.2.3. Slots
  452.  
  453. [change_begin]
  454. An object that has standard-class as its metaclass has zero or more named
  455. slots. The slots of an object are determined by the class of the object. Each
  456. slot can hold one value. The name of a slot is a symbol that is syntactically
  457. valid for use as a variable name.
  458.  
  459. When a slot does not have a value, the slot is said to be unbound. When an
  460. unbound slot is read, the generic function slot-unbound is invoked. The
  461. system-supplied primary method for slot-unbound signals an error.
  462.  
  463. The default initial value form for a slot is defined by the :initform slot
  464. option. When the :initform form is used to supply a value, it is evaluated in
  465. the lexical environment in which the defclass form was evaluated. The :initform
  466. along with the lexical environment in which the defclass form was evaluated is
  467. called a captured :initform. See section 28.1.9.
  468.  
  469. A local slot is defined to be a slot that is visible to exactly one instance,
  470. namely the one in which the slot is allocated. A shared slot is defined to be a
  471. slot that is visible to more than one instance of a given class and its
  472. subclasses.
  473.  
  474. A class is said to define a slot with a given name when the defclass form for
  475. that class contains a slot specifier with that name. Defining a local slot does
  476. not immediately create a slot; it causes a slot to be created each time an
  477. instance of the class is created. Defining a shared slot immediately creates a
  478. slot.
  479.  
  480. The :allocation slot option to defclass controls the kind of slot that is
  481. defined. If the value of the :allocation slot option is :instance, a local slot
  482. is created. If the value of :allocation is :class, a shared slot is created.
  483.  
  484. A slot is said to be accessible in an instance of a class if the slot is
  485. defined by the class of the instance or is inherited from a superclass of that
  486. class. At most one slot of a given name can be accessible in an instance. A
  487. shared slot defined by a class is accessible in all instances of that class. A
  488. detailed explanation of the inheritance of slots is given in section 28.1.3.2.
  489. [change_end]
  490.  
  491. -------------------------------------------------------------------------------
  492.  
  493. 28.1.2.4. Accessing Slots
  494.  
  495. [change_begin]
  496. Slots can be accessed in two ways: by use of the primitive function slot-value
  497. and by use of generic functions generated by the defclass form.
  498.  
  499. The function slot-value can be used with any slot name specified in the
  500. defclass form to access a specific slot accessible in an instance of the given
  501. class.
  502.  
  503. The macro defclass provides syntax for generating methods to read and write
  504. slots. If a reader is requested, a method is automatically generated for
  505. reading the value of the slot, but no method for storing a value into it is
  506. generated. If a writer is requested, a method is automatically generated for
  507. storing a value into the slot, but no method for reading its value is
  508. generated. If an accessor is requested, a method for reading the value of the
  509. slot and a method for storing a value into the slot are automatically
  510. generated. Reader and writer methods are implemented using slot-value.
  511.  
  512. When a reader or writer is specified for a slot, the name of the generic
  513. function to which the generated method belongs is directly specified. If the
  514. name specified for the writer option is the symbol name, the name of the
  515. generic function for writing the slot is the symbol name, and the generic
  516. function takes two arguments: the new value and the instance, in that order. If
  517. the name specified for the accessor option is the symbol name, the name of the
  518. generic function for reading the slot is the symbol name, and the name of the
  519. generic function for writing the slot is the list (setf name).
  520.  
  521. A generic function created or modified by supplying reader, writer, or accessor
  522. slot options can be treated exactly as an ordinary generic function.
  523.  
  524. Note that slot-value can be used to read or write the value of a slot whether
  525. or not reader or writer methods exist for that slot. When slot-value is used,
  526. no reader or writer methods are invoked.
  527.  
  528. The macro with-slots can be used to establish a lexical environment in which
  529. specified slots are lexically available as if they were variables. The macro
  530. with-slots invokes the function slot-value to access the specified slots.
  531.  
  532. The macro with-accessors can be used to establish a lexical environment in
  533. which specified slots are lexically available through their accessors as if
  534. they were variables. The macro with-accessors invokes the appropriate accessors
  535. to access the specified slots. Any accessors specified by with-accessors must
  536. already have been defined before they are used.
  537.  
  538. [change_end]
  539.  
  540. -------------------------------------------------------------------------------
  541.  
  542. 28.1.3. Inheritance
  543.  
  544. [change_begin]
  545. A class can inherit methods, slots, and some defclass options from its
  546. superclasses. The following sections describe the inheritance of methods, the
  547. inheritance of slots and slot options, and the inheritance of class options.
  548. [change_end]
  549.  
  550. -------------------------------------------------------------------------------
  551.  
  552.    *  Inheritance of Methods
  553.    *  Inheritance of Slots and Slot Options
  554.    *  Inheritance of Class Options
  555.    *  Examples
  556.  
  557. -------------------------------------------------------------------------------
  558.  
  559. 28.1.3.1. Inheritance of Methods
  560.  
  561. [change_begin]
  562. A subclass inherits methods in the sense that any method applicable to all
  563. instances of a class is also applicable to all instances of any subclass of
  564. that class.
  565.  
  566. The inheritance of methods acts the same way regardless of whether the method
  567. was created by using one of the method-defining forms or by using one of the
  568. defclass options that causes methods to be generated automatically.
  569.  
  570. The inheritance of methods is described in detail in section 28.1.7.
  571. [change_end]
  572.  
  573. -------------------------------------------------------------------------------
  574.  
  575. 28.1.3.2. Inheritance of Slots and Slot Options
  576.  
  577. [change_begin]
  578. The set of names of all slots accessible in an instance of a class C is the
  579. union of the sets of names of slots defined by C and its superclasses. The
  580. structure of an instance is the set of names of local slots in that instance.
  581.  
  582. In the simplest case, only one class among C and its superclasses defines a
  583. slot with a given slot name. If a slot is defined by a superclass of C, the
  584. slot is said to be inherited. The characteristics of the slot are determined by
  585. the slot specifier of the defining class. Consider the defining class for a
  586. slot S. If the value of the :allocation slot option is :instance, then S is a
  587. local slot and each instance of C has its own slot named S that stores its own
  588. value. If the value of the :allocation slot option is :class, then S is a
  589. shared slot, the class that defined S stores the value, and all instances of C
  590. can access that single slot. If the :allocation slot option is omitted,
  591. :instance is used.
  592.  
  593. In general, more than one class among C and its superclasses can define a slot
  594. with a given name. In such cases, only one slot with the given name is
  595. accessible in an instance of C, and the characteristics of that slot are a
  596. combination of the several slot specifiers, computed as follows:
  597.  
  598.    *  All the slot specifiers for a given slot name are ordered from most
  599.      specific to least specific, according to the order in C's class precedence
  600.      list of the classes that define them. All references to the specificity of
  601.      slot specifiers immediately following refer to this ordering.
  602.  
  603.    *  The allocation of a slot is controlled by the most specific slot
  604.      specifier. If the most specific slot specifier does not contain an
  605.      :allocation slot option, :instance is used. Less specific slot specifiers
  606.      do not affect the allocation.
  607.  
  608.    *  The default initial value form for a slot is the value of the :initform
  609.      slot option in the most specific slot specifier that contains one. If no
  610.      slot specifier contains an :initform slot option, the slot has no default
  611.      initial value form.
  612.  
  613.    *  The contents of a slot will always be of type (and    ...   ) where
  614.      are the values of the :type slot options contained in all of the slot
  615.      specifiers. If no slot specifier contains the :type slot option, the
  616.      contents of the slot will always be of type t. The result of attempting to
  617.      store in a slot a value that does not satisfy the type of the slot is
  618.      undefined.
  619.  
  620.    *  The set of initialization arguments that initialize a given slot is the
  621.      union of the initialization arguments declared in the :initarg slot
  622.      options in all the slot specifiers.
  623.  
  624.    *  The documentation string for a slot is the value of the :documentation
  625.      slot option in the most specific slot specifier that contains one. If no
  626.      slot specifier contains a :documentation slot option, the slot has no
  627.      documentation string.
  628.  
  629. A consequence of the allocation rule is that a shared slot can be shadowed. For
  630. example, if a class    defines a slot named S whose value for the :allocation
  631. slot option is :class, that slot is accessible in instances of    and all of
  632. its subclasses. However, if    is a subclass of    and also defines a slot
  633. named S,   's slot is not shared by instances of    and its subclasses. When a
  634. class    defines a shared slot, any subclass    of    will share this single
  635. slot unless the defclass form for    specifies a slot of the same name or there
  636. is a superclass of    that precedes    in the class precedence list of    that
  637. defines a slot of the same name.
  638.  
  639. A consequence of the type rule is that the value of a slot satisfies the type
  640. constraint of each slot specifier that contributes to that slot. Because the
  641. result of attempting to store in a slot a value that does not satisfy the type
  642. constraint for the slot is undefined, the value in a slot might fail to satisfy
  643. its type constraint.
  644.  
  645. The :reader, :writer, and :accessor slot options create methods rather than
  646. define the characteristics of a slot. Reader and writer methods are inherited
  647. in the sense described in section 28.1.3.1.
  648.  
  649. Methods that access slots use only the name of the slot and the type of the
  650. slot's value. Suppose a superclass provides a method that expects to access a
  651. shared slot of a given name, and a subclass defines a local slot with the same
  652. name. If the method provided by the superclass is used on an instance of the
  653. subclass, the method accesses the local slot.
  654. [change_end]
  655.  
  656. -------------------------------------------------------------------------------
  657.  
  658. 28.1.3.3. Inheritance of Class Options
  659.  
  660. [change_begin]
  661. The :default-initargs class option is inherited. The set of defaulted
  662. initialization arguments for a class is the union of the sets of initialization
  663. arguments specified in the :default-initargs class options of the class and its
  664. superclasses. When more than one default initial value form is supplied for a
  665. given initialization argument, the default initial value form that is used is
  666. the one supplied by the class that is most specific according to the class
  667. precedence list.
  668.  
  669. If a given :default-initargs class option specifies an initialization argument
  670. of the same name more than once, an error is signaled.
  671. [change_end]
  672.  
  673. -------------------------------------------------------------------------------
  674.  
  675. 28.1.3.4. Examples
  676.  
  677. [change_begin]
  678.  
  679. (defclass C1 ()
  680.   ((S1 :initform 5.4 :type number)
  681.    (S2 :allocation :class)))
  682.  
  683. (defclass C2 (C1)
  684.   ((S1 :initform 5 :type integer)
  685.    (S2 :allocation :instance)
  686.    (S3 :accessor C2-S3)))
  687.  
  688. Instances of the class C1 have a local slot named S1, whose default initial
  689. value is 5.4 and whose value should always be a number. The class C1 also has a
  690. shared slot named S2.
  691.  
  692. There is a local slot named S1 in instances of C2. The default initial value of
  693. S1 is 5. The value of S1 will be of type (and integer number). There are also
  694. local slots named S2 and S3 in instances of C2. The class C2 has a method for
  695. C2-S3 for reading the value of slot S3; there is also a method for (setf C2-S3)
  696. that writes the value of S3.
  697. [change_end]
  698.  
  699. -------------------------------------------------------------------------------
  700.  
  701. 28.1.4. Integrating Types and Classes
  702.  
  703. [change_begin]
  704. The Common Lisp Object System maps the space of classes into the Common Lisp
  705. type space. Every class that has a proper name has a corresponding type with
  706. the same name.
  707.  
  708. The proper name of every class is a valid type specifier. In addition, every
  709. class object is a valid type specifier. Thus the expression (typep object
  710. class) evaluates to true if the class of object is class itself or a subclass
  711. of class. The evaluation of the expression (subtypep class1 class2) returns the
  712. values t and t if class1 is a subclass of class2 or if they are the same class;
  713. otherwise it returns the values nil and t. If I is an instance of some class C
  714. named S and C is an instance of standard-class, the evaluation of the
  715. expression (type-of I) will return S if S is the proper name of C; if S is not
  716. the proper name of C, the expression (type-of I) will return C.
  717.  
  718. Because the names of classes and class objects are type specifiers, they may be
  719. used in the special form the and in type declarations.
  720.  
  721. Many but not all of the predefined Common Lisp type specifiers have a
  722. corresponding class with the same proper name as the type. These type
  723. specifiers are listed in table 28-1. For example, the type array has a
  724. corresponding class named array. No type specifier that is a list, such as
  725. (vector double-float 100), has a corresponding class. The form deftype does not
  726. create any classes.
  727.  
  728. Each class that corresponds to a predefined Common Lisp type specifier can be
  729. implemented in one of three ways, at the discretion of each implementation. It
  730. can be a standard class (of the kind defined by defclass), a structure class
  731. (defined by defstruct), or a built-in class (implemented in a special,
  732. non-extensible way).
  733.  
  734. A built-in class is one whose instances have restricted capabilities or special
  735. representations. Attempting to use defclass to define subclasses of a built-in
  736. class signals an error. Calling make-instance to create an instance of a
  737. built-in class signals an error. Calling slot-value on an instance of a
  738. built-in class signals an error. Redefining a built-in class or using
  739. change-class to change the class of an instance to or from a built-in class
  740. signals an error. However, built-in classes can be used as parameter
  741. specializers in methods.
  742.  
  743. It is possible to determine whether a class is a built-in class by checking the
  744. metaclass. A standard class is an instance of standard-class, a built-in class
  745. is an instance of built-in-class, and a structure class is an instance of
  746. structure-class.
  747.  
  748. Each structure type created by defstruct without using the :type option has a
  749. corresponding class. This class is an instance of structure-class.
  750.  
  751. The :include option of defstruct creates a direct subclass of the class that
  752. corresponds to the included structure.
  753.  
  754. The purpose of specifying that many of the standard Common Lisp type specifiers
  755. have a corresponding class is to enable users to write methods that
  756. discriminate on these types. Method selection requires that a class precedence
  757. list can be determined for each class.
  758.  
  759. The hierarchical relationships among the Common Lisp type specifiers are
  760. mirrored by relationships among the classes corresponding to those types. The
  761. existing type hierarchy is used for determining the class precedence list for
  762. each class that corresponds to a predefined Common Lisp type. In some cases,
  763. the first edition did not specify a local precedence order for two supertypes
  764. of a given type specifier. For example, null is a subtype of both symbol and
  765. list, but the first edition did not specify whether symbol is more specific or
  766. less specific than list. The CLOS specification defines those relationships for
  767. all such classes.
  768.  
  769. Table 28-1 lists the set of classes required by the Object System that
  770. correspond to predefined Common Lisp type specifiers. The superclasses of each
  771. such class are presented in order from most specific to most general, thereby
  772. defining the class precedence list for the class. The local precedence order
  773. for each class that corresponds to a Common Lisp type specifier can be derived
  774. from this table.
  775.  
  776. Individual implementations may be extended to define other type specifiers to
  777. have a corresponding class. Individual implementations can be extended to add
  778. other subclass relationships and to add other elements to the class precedence
  779. lists in the above table as long as they do not violate the type relationships
  780. and disjointness requirements specified in section 2.15. A standard class
  781. defined with no direct superclasses is guaranteed to be disjoint from all of
  782. the classes in the table, except for the class named t.
  783.  
  784. [At this point the original CLOS report specified that certain Common Lisp
  785. types were to appear in table 28-1 if and only if X3J13 voted to make them
  786. disjoint from cons, symbol, array, number, and character. X3J13 voted to do so
  787. in June 1988 (DATA-TYPES-HIERARCHY-UNDERSPECIFIED)   . I have added these types
  788. and their class precedence lists to the table; the new types are indicated by
  789. asterisks.-GLS]
  790.  
  791.  
  792. ----------------------------------------------------------------
  793. Table 28-1: Class Precedence Lists for Predefined Types
  794.  
  795. Predefined              Class Precedence List
  796. Common Lisp Type        for Corresponding Class
  797. ==============================================================
  798. array                   (array t)
  799. bit-vector              (bit-vector vector array sequence t)
  800. character               (character t)
  801. complex                 (complex number t)
  802. cons                    (cons list sequence t)
  803. float                   (float number t)
  804. function *              (function t)
  805. hash-table *            (hash-table t)
  806. integer                 (integer rational number t)
  807. list                    (list sequence t)
  808. null                    (null symbol list sequence t)
  809. number                  (number t)
  810. package *               (package t)
  811. pathname *              (pathname t)
  812. random-state *          (random-state t)
  813. ratio                   (ratio rational number t)
  814. rational                (rational number t)
  815. readtable *             (readtable t)
  816. sequence                (sequence t)
  817. stream *                (stream t)
  818. string                  (string vector array sequence t)
  819. symbol                  (symbol t)
  820. t                       (t)
  821. vector                  (vector array sequence t)
  822. ==============================================================
  823.  
  824. [An asterisk indicates a type added to this table as a consequence of
  825. a portion of the CLOS specification that was conditional on X3J13
  826. voting to make that type disjoint from certain other built-in types
  827. (DATA-TYPES-HIERARCHY-UNDERSPECIFIED).---GLS]
  828.  
  829. ----------------------------------------------------------------
  830.  
  831. [change_end]
  832.  
  833. -------------------------------------------------------------------------------
  834.  
  835. 28.1.5. Determining the Class Precedence List
  836.  
  837. [change_begin]
  838. The defclass form for a class provides a total ordering on that class and its
  839. direct superclasses. This ordering is called the local precedence order. It is
  840. an ordered list of the class and its direct superclasses. The class precedence
  841. list for a class C is a total ordering on C and its superclasses that is
  842. consistent with the local precedence orders for C and its superclasses.
  843.  
  844. A class precedes its direct superclasses, and a direct superclass precedes all
  845. other direct superclasses specified to its right in the superclasses list of
  846. the defclass form. For every class C, define
  847.  
  848.  
  849.  
  850. where    are the direct superclasses of C in the order in which they are
  851. mentioned in the defclass form. These ordered pairs generate the total ordering
  852. on the class C and its direct superclasses.
  853.  
  854. Let    be the set of C and its superclasses. Let R be
  855.  
  856.  
  857.  
  858. The set R may or may not generate a partial ordering, depending on whether the
  859.   ,   , are consistent; it is assumed that they are consistent and that R
  860. generates a partial ordering. When the    are not consistent, it is said that R
  861. is inconsistent.
  862.  
  863. To compute the class precedence list for C, topologically sort the elements of
  864.    with respect to the partial ordering generated by R. When the topological
  865. sort must select a class from a set of two or more classes, none of which are
  866. preceded by other classes with respect to R, the class selected is chosen
  867. deterministically, as described below. If R is inconsistent, an error is
  868. signaled.
  869.  
  870. [change_end]
  871. -------------------------------------------------------------------------------
  872.  
  873.    *  Topological Sorting
  874.    *  Examples
  875.  
  876. -------------------------------------------------------------------------------
  877.  
  878. 28.1.5.1. Topological Sorting
  879.  
  880. [change_begin]
  881. Topological sorting proceeds by finding a class C in    such that no other
  882. class precedes that element according to the elements in R. The class C is
  883. placed first in the result. Remove C from   , and remove all pairs of the form
  884. (C, D),   , from R. Repeat the process, adding classes with no predecessors to
  885. the end of the result. Stop when no element can be found that has no
  886. predecessor.
  887.  
  888. If    is not empty and the process has stopped, the set R is inconsistent. If
  889. every class in the finite set of classes is preceded by another, then R
  890. contains a loop. That is, there is a chain of classes    such that    precedes
  891.   , 1 <= i < n, and    precedes   .
  892.  
  893. Sometimes there are several classes from    with no predecessors. In this case
  894. select the one that has a direct subclass rightmost in the class precedence
  895. list computed so far.
  896.  
  897. If there is no such candidate class, R does not generate a partial ordering -
  898. the   ,   , are inconsistent.
  899.  
  900. In more precise terms, let   , m >= 2, be the classes from    with no
  901. predecessors. Let   , n >= 1, be the class precedence list constructed so far.
  902.    is the most specific class, and    is the least specific. Let 1 <= j <= n be
  903. the largest number such that there exists an i where 1 <= i <= m and    is a
  904. direct superclass of   ;    is placed next.
  905.  
  906. The effect of this rule for selecting from a set of classes with no
  907. predecessors is that classes in a simple superclass chain are adjacent in the
  908. class precedence list and that classes in each relatively separated subgraph
  909. are adjacent in the class precedence list. For example, let    and    be
  910. subgraphs whose only element in common is the class J. Suppose that no
  911. superclass of J appears in either    or   . Let    be the bottom of   ; and let
  912.    be the bottom of   . Suppose C is a class whose direct superclasses are
  913. and    in that order; then the class precedence list for C will start with C
  914. and will be followed by all classes in    except J. All the classes of    will
  915. be next. The class J and its superclasses will appear last.
  916. [change_end]
  917.  
  918. -------------------------------------------------------------------------------
  919.  
  920. 28.1.5.2. Examples
  921.  
  922. [change_begin]
  923. This example determines a class precedence list for the class pie. The
  924. following classes are defined:
  925.  
  926. (defclass pie (apple cinnamon) ())
  927. (defclass apple (fruit) ())
  928. (defclass cinnamon (spice) ())
  929. (defclass fruit (food) ())
  930. (defclass spice (food) ())
  931. (defclass food () ())
  932.  
  933. The set S = {pie, apple, cinnamon, fruit, spice, food, standard-object, t}. The
  934. set R = {(pie, apple), (apple, cinnamon), (cinnamon, standard-object), (apple,
  935. fruit), (fruit, standard-object), (cinnamon, spice), (spice, standard-object),
  936. (fruit, food), (food, standard-object), (spice, food), (standard-object, t)}
  937.  
  938. [The original CLOS specification [5,6] contained a minor error in this example:
  939. the pairs (cinnamon, standard-object), (fruit, standard-object), and (spice,
  940. standard-object) were inadvertently omitted from R in the preceding paragraph.
  941. It is important to understand that defclass implicitly appends the class
  942. standard-object to the list of superclasses when the metaclass is
  943. standard-class (the normal situation), in order to insure that standard-object
  944. will be a superclass of every instance of standard-class except standard-object
  945. itself (see section 28.1.2).    is then generated from this augmented list of
  946. superclasses; this is where the extra pairs come from. I have corrected the
  947. example by adding these pairs as appropriate throughout the example. The final
  948. result, the class precedence list for pie, is unchanged.-GLS]
  949.  
  950. The class pie is not preceded by anything, so it comes first; the result so far
  951. is (pie). Remove pie from S and pairs mentioning pie from R to get
  952. S = {apple, cinnamon, fruit, spice, food, standard-object, t} and R = {(apple,
  953. cinnamon), (cinnamon, standard-object), (apple, fruit), (fruit,
  954. standard-object), (cinnamon, spice), (spice, standard-object), (fruit, food),
  955. (food, standard-object), (spice, food), (standard-object, t)}.
  956.  
  957. The class apple is not preceded by anything, so it is next; the result is (pie
  958. apple). Removing apple and the relevant pairs results in
  959. S = {cinnamon, fruit, spice, food, standard-object, t} and R = {(cinnamon,
  960. standard-object), (fruit, standard-object), (cinnamon, spice), (spice,
  961. standard-object), (fruit, food), (food, standard-object), (spice, food),
  962. (standard-object, t)}.
  963.  
  964. The classes cinnamon and fruit are not preceded by anything, so the one with a
  965. direct subclass rightmost in the class precedence list computed so far goes
  966. next. The class apple is a direct subclass of fruit, and the class pie is a
  967. direct subclass of cinnamon. Because apple appears to the right of pie in the
  968. precedence list, fruit goes next, and the result so far is (pie apple fruit).
  969. S = {cinnamon, spice, food, standard-object, t} and R = {(cinnamon,
  970. standard-object), (cinnamon, spice), (spice, standard-object), (food,
  971. standard-object), (spice, food), (standard-object, t)}.
  972.  
  973. The class cinnamon is next, giving the result so far as (pie apple fruit
  974. cinnamon). At this point
  975. S = {spice, food, standard-object, t} and R = {(spice, standard-object), (food,
  976. standard-object), (spice, food), (standard-object, t)}.
  977.  
  978. The classes spice, food, standard-object, and t are then added in that order,
  979. and the final class precedence list for pie is
  980.  
  981. (pie apple fruit cinnamon spice food standard-object t)
  982.  
  983. It is possible to write a set of class definitions that cannot be ordered. For
  984. example:
  985.  
  986. (defclass new-class (fruit apple) ())
  987. (defclass apple (fruit) ())
  988.  
  989. The class fruit must precede apple because the local ordering of superclasses
  990. must be preserved. The class apple must precede fruit because a class always
  991. precedes its own superclasses. When this situation occurs, an error is signaled
  992. when the system tries to compute the class precedence list.
  993.  
  994. The following might appear to be a conflicting set of definitions:
  995.  
  996. (defclass pie (apple cinnamon) ())
  997. (defclass pastry (cinnamon apple) ())
  998. (defclass apple () ())
  999. (defclass cinnamon () ())
  1000.  
  1001. The class precedence list for pie is
  1002.  
  1003. (pie apple cinnamon standard-object t)
  1004.  
  1005. The class precedence list for pastry is
  1006.  
  1007. (pastry cinnamon apple standard-object t)
  1008.  
  1009. It is not a problem for apple to precede cinnamon in the ordering of the
  1010. superclasses of pie but not in the ordering for pastry. However, it is not
  1011. possible to build a new class that has both pie and pastry as superclasses.
  1012. [change_end]
  1013.  
  1014. -------------------------------------------------------------------------------
  1015.  
  1016. 28.1.6. Generic Functions and Methods
  1017.  
  1018. [change_begin]
  1019. A generic function is a function whose behavior depends on the classes or
  1020. identities of the arguments supplied to it. The methods define the
  1021. class-specific behavior and operations of the generic function. The following
  1022. sections describe generic functions and methods.
  1023. [change_end]
  1024.  
  1025. -------------------------------------------------------------------------------
  1026.  
  1027.    *  Introduction to Generic Functions
  1028.    *  Introduction to Methods
  1029.    *  Agreement on Parameter Specializers and Qualifiers
  1030.    *  Congruent Lambda-Lists for All Methods of a Generic Function
  1031.    *  Keyword Arguments in Generic Functions and Methods
  1032.  
  1033. -------------------------------------------------------------------------------
  1034.  
  1035. 28.1.6.1. Introduction to Generic Functions
  1036.  
  1037. [change_begin]
  1038. A generic function object contains a set of methods, a lambda-list, a method
  1039. combination type, and other information.
  1040.  
  1041. Like an ordinary Lisp function, a generic function takes arguments, performs a
  1042. series of operations, and perhaps returns useful values. An ordinary function
  1043. has a single body of code that is always executed when the function is called.
  1044. A generic function has a set of bodies of code of which a subset is selected
  1045. for execution. The selected bodies of code and the manner of their combination
  1046. are determined by the classes or identities of one or more of the arguments to
  1047. the generic function and by its method combination type.
  1048.  
  1049. Ordinary functions and generic functions are called with identical
  1050. function-call syntax.
  1051.  
  1052. Generic functions are true functions that can be passed as arguments, returned
  1053. as values, used as the first argument to funcall and apply, and otherwise used
  1054. in all the ways an ordinary function may be used.
  1055.  
  1056. A name can be given to an ordinary function in one of two ways: a global name
  1057. can be given to a function using the defun construct; a local name can be given
  1058. using the flet or labels special forms. A generic function can be given a
  1059. global name using the defmethod or defgeneric construct. A generic function can
  1060. be given a local name using the generic-flet, generic-labels, or
  1061. with-added-methods special forms. The name of a generic function, like the name
  1062. of an ordinary function, can be either a symbol or a two-element list whose
  1063. first element is setf and whose second element is a symbol. This is true for
  1064. both local and global names.
  1065.  
  1066. The generic-flet special form creates new local generic functions using the set
  1067. of methods specified by the method definitions in the generic-flet form. The
  1068. scoping of generic function names within a generic-flet form is the same as for
  1069. flet.
  1070.  
  1071. The generic-labels special form creates a set of new mutually recursive local
  1072. generic functions using the set of methods specified by the method definitions
  1073. in the generic-labels form. The scoping of generic function names within a
  1074. generic-labels form is the same as for labels.
  1075.  
  1076. The with-added-methods special form creates new local generic functions by
  1077. adding the set of methods specified by the method definitions with a given name
  1078. in the with-added-methods form to copies of the methods of the lexically
  1079. visible generic function of the same name. If there is a lexically visible
  1080. ordinary function of the same name as one of the specified generic functions,
  1081. that function becomes the method function of the default method for the new
  1082. generic function of that name.
  1083.  
  1084. The generic-function macro creates an anonymous generic function with the set
  1085. of methods specified by the method definitions that appear in the
  1086. generic-function form.
  1087.  
  1088. When a defgeneric form is evaluated, one of three actions is taken:
  1089.  
  1090.    *  If a generic function of the given name already exists, the existing
  1091.      generic function object is modified. Methods specified by the current
  1092.      defgeneric form are added, and any methods in the existing generic
  1093.      function that were defined by a previous defgeneric form are removed.
  1094.      Methods added by the current defgeneric form might replace methods defined
  1095.      by defmethod or defclass. No other methods in the generic function are
  1096.      affected or replaced.
  1097.  
  1098.    *  If the given name names a non-generic function, a macro, or a special
  1099.      form, an error is signaled.
  1100.  
  1101.    *  Otherwise a generic function is created with the methods specified by the
  1102.      method definitions in the defgeneric form.
  1103.  
  1104. Some forms specify the options of a generic function, such as the type of
  1105. method combination it uses or its argument precedence order. They will be
  1106. referred to as ``forms that specify generic function options.'' These forms are
  1107. defgeneric, generic-function, generic-flet, generic-labels, and
  1108. with-added-methods.
  1109.  
  1110. Some forms define methods for a generic function. They will be referred to as
  1111. ``method-defining forms.'' These forms are defgeneric, defmethod,
  1112. generic-function, generic-flet, generic-labels, with-added-methods, and
  1113. defclass. Note that all the method-defining forms except defclass and defmethod
  1114. are also forms that specify generic function options.
  1115. [change_end]
  1116.  
  1117. -------------------------------------------------------------------------------
  1118.  
  1119. 28.1.6.2. Introduction to Methods
  1120.  
  1121. [change_begin]
  1122. A method object contains a method function, a sequence of parameter
  1123. specializers that specify when the given method is applicable, a lambda-list,
  1124. and a sequence of qualifiers that are used by the method combination facility
  1125. to distinguish among methods.
  1126.  
  1127. A method object is not a function and cannot be invoked as a function. Various
  1128. mechanisms in the Object System take a method object and invoke its method
  1129. function, as is the case when a generic function is invoked. When this occurs
  1130. it is said that the method is invoked or called.
  1131.  
  1132. A method-defining form contains the code that is to be run when the arguments
  1133. to the generic function cause the method that it defines to be invoked. When a
  1134. method-defining form is evaluated, a method object is created and one of four
  1135. actions is taken:
  1136.  
  1137.    *  If a generic function of the given name already exists and if a method
  1138.      object already exists that agrees with the new one on parameter
  1139.      specializers and qualifiers, the new method object replaces the old one.
  1140.      For a definition of one method agreeing with another on parameter
  1141.      specializers and qualifiers, see section 28.1.6.3.
  1142.  
  1143.    *  If a generic function of the given name already exists and if there is no
  1144.      method object that agrees with the new one on parameter specializers and
  1145.      qualifiers, the existing generic function object is modified to contain
  1146.      the new method object.
  1147.  
  1148.    *  If the given name names a non-generic function, a macro, or a special
  1149.      form, an error is signaled.
  1150.  
  1151.    *  Otherwise a generic function is created with the methods specified by the
  1152.      method-defining form.
  1153.  
  1154. If the lambda-list of a new method is not congruent with the lambda-list of the
  1155. generic function, an error is signaled. If a method-defining form that cannot
  1156. specify generic function options creates a new generic function, a lambda-list
  1157. for that generic function is derived from the lambda-lists of the methods in
  1158. the method-defining form in such a way as to be congruent with them. For a
  1159. discussion of congruence, see section 28.1.6.4.
  1160.  
  1161. Each method has a specialized lambda-list, which determines when that method
  1162. can be applied. A specialized lambda-list is like an ordinary lambda-list
  1163. except that a specialized parameter may occur instead of the name of a required
  1164. parameter. A specialized parameter is a list (variable-name
  1165. parameter-specializer-name), where parameter-specializer-name is either a name
  1166. that names a class or a list (eql form). A parameter specializer name denotes a
  1167. parameter specializer as follows:
  1168.  
  1169.    *  A name that names a class denotes that class.
  1170.  
  1171.    *  The list (eql form) denotes the type specifier (eql object), where object
  1172.      is the result of evaluating form. The form form is evaluated in the
  1173.      lexical environment in which the method-defining form is evaluated. Note
  1174.      that form is evaluated only once, at the time the method is defined, not
  1175.      each time the generic function is called.
  1176.  
  1177. Parameter specializer names are used in macros intended as the user-level
  1178. interface (defmethod), while parameter specializers are used in the functional
  1179. interface.
  1180.  
  1181. [It is very important to understand clearly the distinction made in the
  1182. preceding paragraph. A parameter specializer name has the form of a type
  1183. specifier but is semantically quite different from a type specifier: a
  1184. parameter specializer name of the form (eql form) is not a type specifier, for
  1185. it contains a form to be evaluated. Type specifiers never contain forms to be
  1186. evaluated. All parameter specializers (as opposed to parameter specializer
  1187. names) are valid type specifiers, but not all type specifiers are valid
  1188.  
  1189. names and treat them as specifications for constructing certain type specifiers
  1190. (parameter specializers) that may then be used with such functions as
  1191. find-method.-GLS]
  1192.  
  1193. Only required parameters may be specialized, and there must be a parameter
  1194. specializer for each required parameter. For notational simplicity, if some
  1195. required parameter in a specialized lambda-list in a method-defining form is
  1196. simply a variable name, its parameter specializer defaults to the class named
  1197. t.
  1198.  
  1199. Given a generic function and a set of arguments, an applicable method is a
  1200. method for that generic function whose parameter specializers are satisfied by
  1201. their corresponding arguments. The following definition specifies what it means
  1202. for a method to be applicable and for an argument to satisfy a parameter
  1203. specializer.
  1204.  
  1205. Let    be the required arguments to a generic function in order. Let    be the
  1206. parameter specializers corresponding to the required parameters of the method M
  1207. in order. The method M is applicable when each    satisfies   . If    is a
  1208. class, and if    is an instance of a class C, then it is said that    satisfies
  1209.    when    or when C is a subclass of   . If    is of the form (eql object),
  1210. then it is said that    satisfies    when the function eql applied to    and
  1211. object is true.
  1212.  
  1213. Because a parameter specializer is a type specifier, the function typep can be
  1214. used during method selection to determine whether an argument satisfies a
  1215. parameter specializer. In general a parameter specializer cannot be a type
  1216. specifier list, such as (vector single-float). The only parameter specializer
  1217. that can be a list is (eql object). This requires that Common Lisp define the
  1218. type specifier eql as if the following were evaluated:
  1219.  
  1220. (deftype eql (object) `(member ,object))
  1221.  
  1222. [See section 4.3.-GLS]
  1223.  
  1224. A method all of whose parameter specializers are the class named t is called a
  1225. default method; it is always applicable but may be shadowed by a more specific
  1226. method.
  1227.  
  1228. Methods can have qualifiers, which give the method combination procedure a way
  1229. to distinguish among methods. A method that has one or more qualifiers is
  1230. called a qualified method. A method with no qualifiers is called an unqualified
  1231. method. A qualifier is any object other than a list, that is, any non-nil atom.
  1232. The qualifiers defined by standard method combination and by the built-in
  1233. method combination types are symbols.
  1234.  
  1235. In this specification, the terms primary method and auxiliary method are used
  1236. to partition methods within a method combination type according to their
  1237. intended use. In standard method combination, primary methods are unqualified
  1238. methods, and auxiliary methods are methods with a single qualifier that is one
  1239. of :around, :before, or :after. When a method combination type is defined using
  1240. the short form of define-method-combination, primary methods are methods
  1241. qualified with the name of the type of method combination, and auxiliary
  1242. methods have the qualifier :around. Thus the terms primary method and auxiliary
  1243. method have only a relative definition within a given method combination type.
  1244. [change_end]
  1245.  
  1246. -------------------------------------------------------------------------------
  1247.  
  1248. 28.1.6.3. Agreement on Parameter Specializers and Qualifiers
  1249.  
  1250. [change_begin]
  1251. Two methods are said to agree with each other on parameter specializers and
  1252. qualifiers if the following conditions hold:
  1253.  
  1254.    *  Both methods have the same number of required parameters. Suppose the
  1255.      parameter specializers of the two methods are    and   .
  1256.  
  1257.    *  For each 1 <= i <= n,    agrees with   . The parameter specializer
  1258.      agrees with    if    and    are the same class or if   ,   , and (eql
  1259.        ). Otherwise    and    do not agree.
  1260.  
  1261.    *  The lists of qualifiers of both methods contain the same non-nil atoms in
  1262.      the same order. That is, the lists are equal.
  1263.  
  1264. [change_end]
  1265.  
  1266. -------------------------------------------------------------------------------
  1267.  
  1268. 28.1.6.4. Congruent Lambda-Lists for All Methods of a Generic Function
  1269.  
  1270. [change_begin]
  1271. These rules define the congruence of a set of lambda-lists, including the
  1272. lambda-list of each method for a given generic function and the lambda-list
  1273. specified for the generic function itself, if given.
  1274.  
  1275.    *  Each lambda-list must have the same number of required parameters.
  1276.  
  1277.    *  Each lambda-list must have the same number of optional parameters. Each
  1278.      method can supply its own default for an optional parameter.
  1279.  
  1280.    *  If any lambda-list mentions &rest or &key, each lambda-list must mention
  1281.      one or both of them.
  1282.  
  1283.    *  If the generic function lambda-list mentions &key, each method must
  1284.      accept all of the keyword names mentioned after &key, either by accepting
  1285.      them explicitly, by specifying &allow-other-keys, or by specifying &rest
  1286.      but not &key. Each method can accept additional keyword arguments of its
  1287.      own. The checking of the validity of keyword names is done in the generic
  1288.      function, not in each method. A method is invoked as if the keyword
  1289.      argument pair whose keyword is :allow-other-keys and whose value is t were
  1290.      supplied, though no such argument pair will be passed.
  1291.  
  1292.    *  The use of &allow-other-keys need not be consistent across lambda-lists.
  1293.      If &allow-other-keys is mentioned in the lambda-list of any applicable
  1294.      method or of the generic function, any keyword arguments may be mentioned
  1295.      in the call to the generic function.
  1296.  
  1297.    *  The use of &aux need not be consistent across methods.
  1298.  
  1299. If a method-defining form that cannot specify generic function options creates
  1300. a generic function, and if the lambda-list for the method mentions keyword
  1301. arguments, the lambda-list of the generic function will mention &key (but no
  1302. keyword arguments).
  1303. [change_end]
  1304.  
  1305. -------------------------------------------------------------------------------
  1306.  
  1307. 28.1.6.5. Keyword Arguments in Generic Functions and Methods
  1308.  
  1309. [change_begin]
  1310. When a generic function or any of its methods mentions &key in a lambda-list,
  1311. the specific set of keyword arguments accepted by the generic function varies
  1312. according to the applicable methods. The set of keyword arguments accepted by
  1313. the generic function for a particular call is the union of the keyword
  1314. arguments accepted by all applicable methods and the keyword arguments
  1315. mentioned after &key in the generic function definition, if any. A method that
  1316. has &rest but not &key does not affect the set of acceptable keyword arguments.
  1317. If the lambda-list of any applicable method or of the generic function
  1318. definition contains &allow-other-keys, all keyword arguments are accepted by
  1319. the generic function.
  1320.  
  1321. The lambda-list congruence rules require that each method accept all of the
  1322. keyword arguments mentioned after &key in the generic function definition, by
  1323. accepting them explicitly, by specifying &allow-other-keys, or by specifying
  1324. &rest but not &key. Each method can accept additional keyword arguments of its
  1325. own, in addition to the keyword arguments mentioned in the generic function
  1326. definition.
  1327.  
  1328. If a generic function is passed a keyword argument that no applicable method
  1329. accepts, an error is signaled.
  1330.  
  1331. For example, suppose there are two methods defined for width as follows:
  1332.  
  1333. (defmethod width ((c character-class) &key font) ...)
  1334.  
  1335. (defmethod width ((p picture-class) &key pixel-size) ...)
  1336.  
  1337. Assume that there are no other methods and no generic function definition for
  1338. width. The evaluation of the following form will signal an error because the
  1339. keyword argument :pixel-size is not accepted by the applicable method.
  1340.  
  1341. (width (make-instance 'character-class :char #¥Q)
  1342.        :font 'baskerville :pixel-size 10)
  1343.  
  1344. The evaluation of the following form will signal an error.
  1345.  
  1346. (width (make-instance 'picture-class :glyph (glyph #¥Q))
  1347.        :font 'baskerville :pixel-size 10)
  1348.  
  1349. The evaluation of the following form will not signal an error if the class
  1350. named character-picture-class is a subclass of both picture-class and
  1351. character-class.
  1352.  
  1353. (width (make-instance 'character-picture-class :char #¥Q)
  1354.        :font 'baskerville :pixel-size 10)
  1355.  
  1356. [change_end]
  1357.  
  1358. -------------------------------------------------------------------------------
  1359.  
  1360. 28.1.7. Method Selection and Combination
  1361.  
  1362. [change_begin]
  1363. When a generic function is called with particular arguments, it must determine
  1364. the code to execute. This code is called the effective method for those
  1365. arguments. The effective method is a combination of the applicable methods in
  1366. the generic function. A combination of methods is a Lisp expression that
  1367. contains calls to some or all of the methods. If a generic function is called
  1368. and no methods apply, the generic function no-applicable-method is invoked.
  1369.  
  1370. When the effective method has been determined, it is invoked with the same
  1371. arguments that were passed to the generic function. Whatever values it returns
  1372. are returned as the values of the generic function.
  1373. [change_end]
  1374.  
  1375. -------------------------------------------------------------------------------
  1376.  
  1377.    *  Determining the Effective Method
  1378.    *  Standard Method Combination
  1379.    *  Declarative Method Combination
  1380.    *  Built-in Method Combination Types
  1381.  
  1382. -------------------------------------------------------------------------------
  1383.  
  1384. 28.1.7.1. Determining the Effective Method
  1385.  
  1386. [change_begin]
  1387. The effective method for a set of arguments is determined by the following
  1388. three-step procedure:
  1389.  
  1390.   1.  Select the applicable methods.
  1391.  
  1392.   2.  Sort the applicable methods by precedence order, putting the most
  1393.      specific method first.
  1394.  
  1395.   3.  Apply method combination to the sorted list of applicable methods,
  1396.      producing the effective method.
  1397.  
  1398. Selecting the Applicable Methods. This step is described in section 28.1.6.2.
  1399.  
  1400. Sorting the Applicable Methods by Precedence Order. To compare the precedence
  1401. of two methods, their parameter specializers are examined in order. The default
  1402. examination order is from left to right, but an alternative order may be
  1403. specified by the :argument-precedence-order option to defgeneric or to any of
  1404. the other forms that specify generic function options.
  1405.  
  1406. The corresponding parameter specializers from each method are compared. When a
  1407. pair of parameter specializers are equal, the next pair are compared for
  1408. equality. If all corresponding parameter specializers are equal, the two
  1409. methods must have different qualifiers; in this case, either method can be
  1410. selected to precede the other.
  1411.  
  1412. If some corresponding parameter specializers are not equal, the first pair of
  1413. parameter specializers that are not equal determines the precedence. If both
  1414. parameter specializers are classes, the more specific of the two methods is the
  1415. method whose parameter specializer appears earlier in the class precedence list
  1416. of the corresponding argument. Because of the way in which the set of
  1417. applicable methods is chosen, the parameter specializers are guaranteed to be
  1418. present in the class precedence list of the class of the argument.
  1419.  
  1420. If just one parameter specializer is (eql object), the method with that
  1421. parameter specializer precedes the other method. If both parameter specializers
  1422. are eql forms, the specializers must be the same (otherwise the two methods
  1423. would not both have been applicable to this argument).
  1424.  
  1425. The resulting list of applicable methods has the most specific method first and
  1426. the least specific method last.
  1427.  
  1428. Applying Method Combination to the Sorted List of Applicable Methods. In the
  1429. simple case-if standard method combination is used and all applicable methods
  1430. are primary methods-the effective method is the most specific method. That
  1431. method can call the next most specific method by using the function
  1432. call-next-method. The method that call-next-method will call is referred to as
  1433. the next method. The predicate next-method-p tests whether a next method
  1434. exists. If call-next-method is called and there is no next most specific
  1435. method, the generic function no-next-method is invoked.
  1436.  
  1437. In general, the effective method is some combination of the applicable methods.
  1438. It is defined by a Lisp form that contains calls to some or all of the
  1439. applicable methods, returns the value or values that will be returned as the
  1440. value or values of the generic function, and optionally makes some of the
  1441. methods accessible by means of call-next-method. This Lisp form is the body of
  1442. the effective method; it is augmented with an appropriate lambda-list to make
  1443. it a function.
  1444.  
  1445. The role of each method in the effective method is determined by its method
  1446. qualifiers and the specificity of the method. A qualifier serves to mark a
  1447. method, and the meaning of a qualifier is determined by the way that these
  1448. marks are used by this step of the procedure. If an applicable method has an
  1449. unrecognized qualifier, this step signals an error and does not include that
  1450. method in the effective method.
  1451.  
  1452. When standard method combination is used together with qualified methods, the
  1453. effective method is produced as described in section 28.1.7.2.
  1454.  
  1455. Another type of method combination can be specified by using the
  1456. :method-combination option of defgeneric or of any of the other forms that
  1457. specify generic function options. In this way this step of the procedure can be
  1458. customized.
  1459.  
  1460. New types of method combination can be defined by using the
  1461. define-method-combination macro.
  1462.  
  1463. The meta-object level also offers a mechanism for defining new types of method
  1464. combination. The generic function compute-effective-method receives as
  1465. arguments the generic function, the method combination object, and the sorted
  1466. list of applicable methods. It returns the Lisp form that defines the effective
  1467. method. A method for compute-effective-method can be defined directly by using
  1468. defmethod or indirectly by using define-method-combination. A method
  1469. combination object is an object that encapsulates the method combination type
  1470. and options specified by the :method-combination option to forms that specify
  1471. generic function options.
  1472.  
  1473. -------------------------------------------------------------------------------
  1474. Implementation note: In the simplest implementation, the generic function would
  1475. compute the effective method each time it was called. In practice, this will be
  1476. too inefficient for some implementations. Instead, these implementations might
  1477. employ a variety of optimizations of the three-step procedure. Some
  1478. illustrative examples of such optimizations are the following:
  1479.  
  1480.    *  Use a hash table keyed by the class of the arguments to store the
  1481.      effective method.
  1482.  
  1483.    *  Compile the effective method and save the resulting compiled function in
  1484.      a table.
  1485.  
  1486.    *  Recognize the Lisp form as an instance of a pattern of control structure
  1487.      and substitute a closure that implements that structure.
  1488.  
  1489.    *  Examine the parameter specializers of all methods for the generic
  1490.      function and enumerate all possible effective methods. Combine the
  1491.      effective methods, together with code to select from among them, into a
  1492.      single function and compile that function. Call that function whenever the
  1493.      generic function is called.
  1494.  
  1495. -------------------------------------------------------------------------------
  1496. [change_end]
  1497.  
  1498. -------------------------------------------------------------------------------
  1499.  
  1500. 28.1.7.2. Standard Method Combination
  1501.  
  1502. [change_begin]
  1503. Standard method combination is supported by the class
  1504. standard-generic-function. It is used if no other type of method combination is
  1505. specified or if the built-in method combination type standard is specified.
  1506.  
  1507. Primary methods define the main action of the effective method, while auxiliary
  1508. methods modify that action in one of three ways. A primary method has no method
  1509. qualifiers.
  1510.  
  1511. An auxiliary method is a method whose method qualifier is :before, :after, or
  1512. :around. Standard method combination allows no more than one qualifier per
  1513. method; if a method definition specifies more than one qualifier per method, an
  1514. error is signaled.
  1515.  
  1516.    *  A :before method has the keyword :before as its only qualifier. A :before
  1517.      method specifies code that is to be run before any primary method.
  1518.  
  1519.    *  An :after method has the keyword :after as its only qualifier. An :after
  1520.      method specifies code that is to be run after primary methods.
  1521.  
  1522.    *  An :around method has the keyword :around as its only qualifier. An
  1523.      :around method specifies code that is to be run instead of other
  1524.      applicable methods but that is able to cause some of them to be run.
  1525.  
  1526. The semantics of standard method combination are as follows:
  1527.  
  1528.    *  If there are any :around methods, the most specific :around method is
  1529.      called. It supplies the value or values of the generic function.
  1530.  
  1531.    *  Inside the body of an :around method, call-next-method can be used to
  1532.      call the next method. When the next method returns, the :around method can
  1533.      execute more code, perhaps based on the returned value or values. The
  1534.      generic function no-next-method is invoked if call-next-method is used and
  1535.      there is no applicable method to call. The function next-method-p may be
  1536.      used to determine whether a next method exists.
  1537.  
  1538.    *  If an :around method invokes call-next-method, the next most specific
  1539.      :around method is called, if one is applicable. If there are no :around
  1540.      methods or if call-next-method is called by the least specific :around
  1541.      method, the other methods are called as follows:
  1542.  
  1543.         o  All the :before methods are called, in most-specific-first order.
  1544.           Their values are ignored. An error is signaled if call-next-method is
  1545.           used in a :before method.
  1546.  
  1547.         o  The most specific primary method is called. Inside the body of a
  1548.           primary method, call-next-method may be used to call the next most
  1549.           specific primary method. When that method returns, the previous
  1550.           primary method can execute more code, perhaps based on the returned
  1551.           value or values. The generic function no-next-method is invoked if
  1552.           call-next-method is used and there are no more applicable primary
  1553.           methods. The function next-method-p may be used to determine whether
  1554.           a next method exists. If call-next-method is not used, only the most
  1555.           specific primary method is called.
  1556.  
  1557.         o  All the :after methods are called in most-specific-last order. Their
  1558.           values are ignored. An error is signaled if call-next-method is used
  1559.           in an :after method.
  1560.  
  1561.    *  If no :around methods were invoked, the most specific primary method
  1562.      supplies the value or values returned by the generic function. The value
  1563.      or values returned by the invocation of call-next-method in the least
  1564.      specific :around method are those returned by the most specific primary
  1565.      method.
  1566.  
  1567. In standard method combination, if there is an applicable method but no
  1568. applicable primary method, an error is signaled.
  1569.  
  1570. The :before methods are run in most-specific-first order and the :after methods
  1571. are run in least-specific-first order. The design rationale for this difference
  1572. can be illustrated with an example. Suppose class    modifies the behavior of
  1573. its superclass,   , by adding :before and :after methods. Whether the behavior
  1574. of the class    is defined directly by methods on    or is inherited from its
  1575. superclasses does not affect the relative order of invocation of methods on
  1576. instances of the class   . Class   's :before method runs before all of class
  1577.   's methods. Class   's :after method runs after all of class   's methods.
  1578.  
  1579. By contrast, all :around methods run before any other methods run. Thus a less
  1580. specific :around method runs before a more specific primary method.
  1581.  
  1582. If only primary methods are used and if call-next-method is not used, only the
  1583. most specific method is invoked; that is, more specific methods shadow more
  1584. general ones.
  1585. [change_end]
  1586.  
  1587. -------------------------------------------------------------------------------
  1588.  
  1589. 28.1.7.3. Declarative Method Combination
  1590.  
  1591. [change_begin]
  1592. The macro define-method-combination defines new forms of method combination. It
  1593. provides a mechanism for customizing the production of the effective method.
  1594. The default procedure for producing an effective method is described in section
  1595. 28.1.7.2. There are two forms of define-method-combination. The short form is a
  1596. simple facility; the long form is more powerful and more verbose. The long form
  1597. resembles defmacro in that the body is an expression that computes a Lisp form;
  1598. it provides mechanisms for implementing arbitrary control structures within
  1599. method combination and for arbitrary processing of method qualifiers. The
  1600. syntax and use of both forms of define-method-combination are explained in
  1601. section 28.2.
  1602. [change_end]
  1603.  
  1604. -------------------------------------------------------------------------------
  1605.  
  1606. 28.1.7.4. Built-in Method Combination Types
  1607.  
  1608. [change_begin]
  1609. The Common Lisp Object System provides a set of built-in method combination
  1610. types. To specify that a generic function is to use one of these method
  1611. combination types, the name of the method combination type is given as the
  1612. argument to the :method-combination option to defgeneric or to the
  1613. :method-combination option to any of the other forms that specify generic
  1614. function options.
  1615.  
  1616. The names of the built-in method combination types are +, and, append, list,
  1617. max, min, nconc, or, progn, and standard.
  1618.  
  1619. The semantics of the standard built-in method combination type were described
  1620. in section 28.1.7.2. The other built-in method combination types are called
  1621. simple built-in method combination types.
  1622.  
  1623. The simple built-in method combination types act as though they were defined by
  1624. the short form of define-method-combination. They recognize two roles for
  1625. methods:
  1626.  
  1627.    *  An :around method has the keyword symbol :around as its sole qualifier.
  1628.      The meaning of :around methods is the same as in standard method
  1629.      combination. Use of the functions call-next-method and next-method-p is
  1630.      supported in :around methods.
  1631.  
  1632.    *  A primary method has the name of the method combination type as its sole
  1633.      qualifier. For example, the built-in method combination type and
  1634.      recognizes methods whose sole qualifier is and; these are primary methods.
  1635.      Use of the functions call-next-method and next-method-p is not supported
  1636.      in primary methods.
  1637.  
  1638. The semantics of the simple built-in method combination types are as follows:
  1639.  
  1640.    *  If there are any :around methods, the most specific :around method is
  1641.      called. It supplies the value or values of the generic function.
  1642.  
  1643.    *  Inside the body of an :around method, the function call-next-method can
  1644.      be used to call the next method. The generic function no-next-method is
  1645.      invoked if call-next-method is used and there is no applicable method to
  1646.      call. The function next-method-p may be used to determine whether a next
  1647.      method exists. When the next method returns, the :around method can
  1648.      execute more code, perhaps based on the returned value or values.
  1649.  
  1650.    *  If an :around method invokes call-next-method, the next most specific
  1651.      :around method is called, if one is applicable. If there are no :around
  1652.      methods or if call-next-method is called by the least specific :around
  1653.      method, a Lisp form derived from the name of the built-in method
  1654.      combination type and from the list of applicable primary methods is
  1655.      evaluated to produce the value of the generic function. Suppose the name
  1656.      of the method combination type is operator and the call to the generic
  1657.      function is of the form
  1658.  
  1659.      (generic-function    ...   )
  1660.  
  1661.      Let    be the applicable primary methods in order; then the derived Lisp
  1662.      form is
  1663.  
  1664.      (operator
  1665.      ...   )
  1666.  
  1667.      If the expression    is evaluated, the method    will be applied to the
  1668.      arguments   . For example, if operator is or, the expression    is
  1669.      evaluated only if   , 1 <= j < i, returned nil.
  1670.  
  1671.      The default order for the primary methods is :most-specific-first.
  1672.      However, the order can be reversed by supplying :most-specific-last as the
  1673.      second argument to the :method-combination option.
  1674.  
  1675. The simple built-in method combination types require exactly one qualifier per
  1676. method. An error is signaled if there are applicable methods with no qualifiers
  1677. or with qualifiers that are not supported by the method combination type. An
  1678. error is signaled if there are applicable :around methods and no applicable
  1679. primary methods.
  1680. [change_end]
  1681.  
  1682. -------------------------------------------------------------------------------
  1683.  
  1684. 28.1.8. Meta-objects
  1685.  
  1686. [change_begin]
  1687. The implementation of the Object System manipulates classes, methods, and
  1688. generic functions. The meta-object protocol specifies a set of generic
  1689. functions defined by methods on classes; the behavior of those generic
  1690. functions defines the behavior of the Object System. The instances of the
  1691. classes on which those methods are defined are called meta-objects. Programming
  1692. at the meta-object protocol level involves defining new classes of meta-objects
  1693. along with methods specialized on these classes.
  1694. [change_end]
  1695.  
  1696. -------------------------------------------------------------------------------
  1697.  
  1698.    *  Metaclasses
  1699.    *  Standard Metaclasses
  1700.    *  Standard Meta-objects
  1701.  
  1702. -------------------------------------------------------------------------------
  1703.  
  1704. 28.1.8.1. Metaclasses
  1705.  
  1706. [change_begin]
  1707. The metaclass of an object is the class of its class. The metaclass determines
  1708. the representation of instances of its instances and the forms of inheritance
  1709. used by its instances for slot descriptions and method inheritance. The
  1710. metaclass mechanism can be used to provide particular forms of optimization or
  1711. to tailor the Common Lisp Object System for particular uses. The protocol for
  1712. defining metaclasses is discussed in the third part of the CLOS specification,
  1713. The Common Lisp Object System Meta-Object Protocol. [The third part has not yet
  1714. been approved by X3J13 for inclusion in the forthcoming Common Lisp standard
  1715. and is not included in this book.-GLS]
  1716. [change_end]
  1717.  
  1718. -------------------------------------------------------------------------------
  1719.  
  1720. 28.1.8.2. Standard Metaclasses
  1721.  
  1722. [change_begin]
  1723. The Common Lisp Object System provides a number of predefined metaclasses.
  1724. These include the classes standard-class, built-in-class, and structure-class:
  1725.  
  1726.    *  The class standard-class is the default class of classes defined by
  1727.      defclass.
  1728.  
  1729.    *  The class built-in-class is the class whose instances are classes that
  1730.      have special implementations with restricted capabilities. Any class that
  1731.      corresponds to a standard Common Lisp type might be an instance of
  1732.      built-in-class. The predefined Common Lisp type specifiers that are
  1733.      required to have corresponding classes are listed in table 28-1. It is
  1734.      implementation-dependent whether each of these classes is implemented as a
  1735.      built-in class.
  1736.  
  1737.    *  All classes defined by means of defstruct are instances of
  1738.      structure-class.
  1739.  
  1740. [change_end]
  1741.  
  1742. -------------------------------------------------------------------------------
  1743.  
  1744. 28.1.8.3. Standard Meta-objects
  1745.  
  1746. [change_begin]
  1747. The Object System supplies a standard set of meta-objects, called standard
  1748. meta-objects. These include the class standard-object and instances of the
  1749. classes standard-method, standard-generic-function, and method-combination.
  1750.  
  1751.    *  The class standard-method is the default class of methods that are
  1752.      defined by the forms defmethod, defgeneric, generic-function,
  1753.      generic-flet, generic-labels, and with-added-methods.
  1754.  
  1755.    *  The class standard-generic-function is the default class of generic
  1756.      functions defined by the forms defmethod, defgeneric, generic-function,
  1757.      generic-flet, generic-labels, with-added-methods, and defclass.
  1758.  
  1759.    *  The class named standard-object is an instance of the class
  1760.      standard-class and is a superclass of every class that is an instance of
  1761.      standard-class except itself.
  1762.  
  1763.    *  Every method combination object is an instance of a subclass of the class
  1764.      method-combination.
  1765.  
  1766. [change_end]
  1767.  
  1768. -------------------------------------------------------------------------------
  1769.  
  1770. 28.1.9. Object Creation and Initialization
  1771.  
  1772. [change_begin]
  1773. The generic function make-instance creates and returns a new instance of a
  1774. class. The first argument is a class or the name of a class, and the remaining
  1775. arguments form an initialization argument list.
  1776.  
  1777. The initialization of a new instance consists of several distinct steps,
  1778. including the following: combining the explicitly supplied initialization
  1779. arguments with default values for the unsupplied initialization arguments,
  1780. checking the validity of the initialization arguments, allocating storage for
  1781. the instance, filling slots with values, and executing user-supplied methods
  1782. that perform additional initialization. Each step of make-instance is
  1783. implemented by a generic function to provide a mechanism for customizing that
  1784. step. In addition, make-instance is itself a generic function and thus also can
  1785. be customized.
  1786.  
  1787. The Object System specifies system-supplied primary methods for each step and
  1788. thus specifies a well-defined standard behavior for the entire initialization
  1789. process. The standard behavior provides four simple mechanisms for controlling
  1790. initialization:
  1791.  
  1792.    *  Declaring a symbol to be an initialization argument for a slot. An
  1793.      initialization argument is declared by using the :initarg slot option to
  1794.      defclass. This provides a mechanism for supplying a value for a slot in a
  1795.      call to make-instance.
  1796.  
  1797.    *  Supplying a default value form for an initialization argument. Default
  1798.      value forms for initialization arguments are defined by using the
  1799.      :default-initargs class option to defclass. If an initialization argument
  1800.      is not explicitly provided as an argument to make-instance, the default
  1801.      value form is evaluated in the lexical environment of the defclass form
  1802.      that defined it, and the resulting value is used as the value of the
  1803.      initialization argument.
  1804.  
  1805.    *  Supplying a default initial value form for a slot. A default initial
  1806.      value form for a slot is defined by using the :initform slot option to
  1807.      defclass. If no initialization argument associated with that slot is given
  1808.      as an argument to make-instance or is defaulted by :default-initargs, this
  1809.      default initial value form is evaluated in the lexical environment of the
  1810.      defclass form that defined it, and the resulting value is stored in the
  1811.      slot. The :initform form for a local slot may be used when creating an
  1812.      instance, when updating an instance to conform to a redefined class, or
  1813.      when updating an instance to conform to the definition of a different
  1814.      class. The :initform form for a shared slot may be used when defining or
  1815.      re-defining the class.
  1816.  
  1817.    *  Defining methods for initialize-instance and shared-initialize. The
  1818.      slot-filling behavior described above is implemented by a system-supplied
  1819.      primary method for initialize-instance which invokes shared-initialize.
  1820.      The generic function shared-initialize implements the parts of
  1821.      initialization shared by these four situations: when making an instance,
  1822.      when re-initializing an instance, when updating an instance to conform to
  1823.      a redefined class, and when updating an instance to conform to the
  1824.      definition of a different class. The system-supplied primary method for
  1825.      shared-initialize directly implements the slot-filling behavior described
  1826.      above, and initialize-instance simply invokes shared-initialize.
  1827.  
  1828. [change_end]
  1829.  
  1830. -------------------------------------------------------------------------------
  1831.  
  1832.    *  Initialization Arguments
  1833.    *  Declaring the Validity of Initialization Arguments
  1834.    *  Defaulting of Initialization Arguments
  1835.    *  Rules for Initialization Arguments
  1836.    *  Shared-Initialize
  1837.    *  Initialize-Instance
  1838.    *  Definitions of Make-Instance and Initialize-Instance
  1839.  
  1840. -------------------------------------------------------------------------------
  1841.  
  1842. 28.1.9.1. Initialization Arguments
  1843.  
  1844. [change_begin]
  1845. An initialization argument controls object creation and initialization. It is
  1846. often convenient to use keyword symbols to name initialization arguments, but
  1847. the name of an initialization argument can be any symbol, including nil. An
  1848. initialization argument can be used in two ways: to fill a slot with a value or
  1849. to provide an argument for an initialization method. A single initialization
  1850. argument can be used for both purposes.
  1851.  
  1852. An initialization argument list is a list of alternating initialization
  1853. argument names and values. Its structure is identical to a property list and
  1854. also to the portion of an argument list processed for &key parameters. As in
  1855. those lists, if an initialization argument name appears more than once in an
  1856. initialization argument list, the leftmost occurrence supplies the value and
  1857. the remaining occurrences are ignored. The arguments to make-instance (after
  1858. the first argument) form an initialization argument list. Error checking of
  1859. initialization argument names is disabled if the keyword argument pair whose
  1860. keyword is :allow-other-keys and whose value is non-nil appears in the
  1861. initialization argument list.
  1862.  
  1863. An initialization argument can be associated with a slot. If the initialization
  1864. argument has a value in the initialization argument list, the value is stored
  1865. into the slot of the newly created object, overriding any :initform form
  1866. associated with the slot. A single initialization argument can initialize more
  1867. than one slot. An initialization argument that initializes a shared slot stores
  1868. its value into the shared slot, replacing any previous value.
  1869.  
  1870. An initialization argument can be associated with a method. When an object is
  1871. created and a particular initialization argument is supplied, the generic
  1872. functions initialize-instance, shared-initialize, and allocate-instance are
  1873. called with that initialization argument's name and value as a keyword argument
  1874. pair. If a value for the initialization argument is not supplied in the
  1875. initialization argument list, the method's lambda-list supplies a default
  1876. value.
  1877.  
  1878. Initialization arguments are used in four situations: when making an instance,
  1879. when re-initializing an instance, when updating an instance to conform to a
  1880. redefined class, and when updating an instance to conform to the definition of
  1881. a different class.
  1882.  
  1883. Because initialization arguments are used to control the creation and
  1884. initialization of an instance of some particular class, we say that an
  1885. initialization argument is ``an initialization argument for'' that class.
  1886. [change_end]
  1887.  
  1888. -------------------------------------------------------------------------------
  1889.  
  1890. 28.1.9.2. Declaring the Validity of Initialization Arguments
  1891.  
  1892. [change_begin]
  1893. Initialization arguments are checked for validity in each of the four
  1894. situations that use them. An initialization argument may be valid in one
  1895. situation and not another. For example, the system-supplied primary method for
  1896. make-instance defined for the class standard-class checks the validity of its
  1897. initialization arguments and signals an error if an initialization argument is
  1898. supplied that is not declared valid in that situation.
  1899.  
  1900. There are two means of declaring initialization arguments valid.
  1901.  
  1902.    *  Initialization arguments that fill slots are declared valid by the
  1903.      :initarg slot option to defclass. The :initarg slot option is inherited
  1904.      from superclasses. Thus the set of valid initialization arguments that
  1905.      fill slots for a class is the union of the initialization arguments that
  1906.      fill slots declared valid by that class and its superclasses.
  1907.      Initialization arguments that fill slots are valid in all four contexts.
  1908.  
  1909.    *  Initialization arguments that supply arguments to methods are declared
  1910.      valid by defining those methods. The keyword name of each keyword
  1911.      parameter specified in the method's lambda-list becomes an initialization
  1912.      argument for all classes for which the method is applicable. Thus method
  1913.      inheritance controls the set of valid initialization arguments that supply
  1914.      arguments to methods. The generic functions for which method definitions
  1915.      serve to declare initialization arguments valid are as follows:
  1916.  
  1917.         o  Making an instance of a class: allocate-instance,
  1918.           initialize-instance, and shared-initialize. Initialization arguments
  1919.           declared valid by these methods are valid when making an instance of
  1920.           a class.
  1921.  
  1922.         o  Re-initializing an instance: the functions reinitialize-instance and
  1923.           shared-initialize. Initialization arguments declared valid by these
  1924.           methods are valid when re-initializing an instance.
  1925.  
  1926.         o  Updating an instance to conform to a redefined class:
  1927.           update-instance-for-redefined-class and shared-initialize.
  1928.           Initialization arguments declared valid by these methods are valid
  1929.           when updating an instance to conform to a redefined class.
  1930.  
  1931.         o  Updating an instance to conform to the definition of a different
  1932.           class: update-instance-for-different-class and shared-initialize.
  1933.           Initialization arguments declared valid by these methods are valid
  1934.           when updating an instance to conform to the definition of a different
  1935.           class.
  1936.  
  1937. The set of valid initialization arguments for a class is the set of valid
  1938. initialization arguments that either fill slots or supply arguments to methods,
  1939. along with the predefined initialization argument :allow-other-keys. The
  1940. default value for :allow-other-keys is nil. The meaning of :allow-other-keys is
  1941. the same here as when it is passed to an ordinary function.
  1942. [change_end]
  1943.  
  1944. -------------------------------------------------------------------------------
  1945.  
  1946. 28.1.9.3. Defaulting of Initialization Arguments
  1947.  
  1948. [change_begin]
  1949. A default value form can be supplied for an initialization argument by using
  1950. the :default-initargs class option. If an initialization argument is declared
  1951. valid by some particular class, its default value form might be specified by a
  1952. different class. In this case :default-initargs is used to supply a default
  1953. value for an inherited initialization argument.
  1954.  
  1955. The :default-initargs option is used only to provide default values for
  1956. initialization arguments; it does not declare a symbol as a valid
  1957. initialization argument name. Furthermore, the :default-initargs option is used
  1958. only to provide default values for initialization arguments when making an
  1959. instance.
  1960.  
  1961. The argument to the :default-initargs class option is a list of alternating
  1962. initialization argument names and forms. Each form is the default value form
  1963. for the corresponding initialization argument. The default value form of an
  1964. initialization argument is used and evaluated only if that initialization
  1965. argument does not appear in the arguments to make-instance and is not defaulted
  1966. by a more specific class. The default value form is evaluated in the lexical
  1967. environment of the defclass form that supplied it; the result is used as the
  1968. initialization argument's value.
  1969.  
  1970. The initialization arguments supplied to make-instance are combined with
  1971. defaulted initialization arguments to produce a defaulted initialization
  1972. argument list. A defaulted initialization argument list is a list of
  1973. alternating initialization argument names and values in which unsupplied
  1974. initialization arguments are defaulted and in which the explicitly supplied
  1975. initialization arguments appear earlier in the list than the defaulted
  1976. initialization arguments. Defaulted initialization arguments are ordered
  1977. according to the order in the class precedence list of the classes that
  1978. supplied the default values.
  1979.  
  1980. There is a distinction between the purposes of the :default-initargs and the
  1981. :initform options with respect to the initialization of slots. The
  1982. :default-initargs class option provides a mechanism for the user to give a
  1983. default value form for an initialization argument without knowing whether the
  1984. initialization argument initializes a slot or is passed to a method. If that
  1985. initialization argument is not explicitly supplied in a call to make-instance,
  1986. the default value form is used, just as if it had been supplied in the call. In
  1987. contrast, the :initform slot option provides a mechanism for the user to give a
  1988. default initial value form for a slot. An :initform form is used to initialize
  1989. a slot only if no initialization argument associated with that slot is given as
  1990. an argument to make-instance or is defaulted by :default-initargs.
  1991.  
  1992. The order of evaluation of default value forms for initialization arguments and
  1993. the order of evaluation of :initform forms are undefined. If the order of
  1994. evaluation matters, use initialize-instance or shared-initialize methods.
  1995. [change_end]
  1996.  
  1997. -------------------------------------------------------------------------------
  1998.  
  1999. 28.1.9.4. Rules for Initialization Arguments
  2000.  
  2001. [change_begin]
  2002. The :initarg slot option may be specified more than once for a given slot. The
  2003. following rules specify when initialization arguments may be multiply defined:
  2004.  
  2005.    *  A given initialization argument can be used to initialize more than one
  2006.      slot if the same initialization argument name appears in more than one
  2007.      :initarg slot option.
  2008.  
  2009.    *  A given initialization argument name can appear in the lambda-list of
  2010.      more than one initialization method.
  2011.  
  2012.    *  A given initialization argument name can appear both in an :initarg slot
  2013.      option and in the lambda-list of an initialization method.
  2014.  
  2015. If two or more initialization arguments that initialize the same slot are given
  2016. in the arguments to make-instance, the leftmost of these initialization
  2017. arguments in the initialization argument list supplies the value, even if the
  2018. initialization arguments have different names.
  2019.  
  2020. If two or more different initialization arguments that initialize the same slot
  2021. have default values and none is given explicitly in the arguments to
  2022. make-instance, the initialization argument that appears in a :default-initargs
  2023. class option in the most specific of the classes supplies the value. If a
  2024. single :default-initargs class option specifies two or more initialization
  2025. arguments that initialize the same slot and none is given explicitly in the
  2026. arguments to make-instance, the leftmost argument in the :default-initargs
  2027. class option supplies the value, and the values of the remaining default value
  2028. forms are ignored.
  2029.  
  2030. Initialization arguments given explicitly in the arguments to make-instance
  2031. appear to the left of defaulted initialization arguments. Suppose that the
  2032. classes    and    supply the values of defaulted initialization arguments for
  2033. different slots, and suppose that    is more specific than   ; then the
  2034. defaulted initialization argument whose value is supplied by    is to the left
  2035. of the defaulted initialization argument whose value is supplied by    in the
  2036. defaulted initialization argument list. If a single :default-initargs class
  2037. option supplies the values of initialization arguments for two different slots,
  2038. the initialization argument whose value is specified farther to the left in the
  2039. default-initargs class option appears farther to the left in the defaulted
  2040. initialization argument list.
  2041.  
  2042. If a slot has both an :initform form and an :initarg slot option, and the
  2043. initialization argument is defaulted using :default-initargs or is supplied to
  2044. make-instance, the captured :initform form is neither used nor evaluated.
  2045.  
  2046. The following is an example of the preceding rules:
  2047.  
  2048. (defclass q () ((x :initarg a)))
  2049.  
  2050. (defclass r (q) ((x :initarg b))
  2051.   (:default-initargs a 1 b 2))
  2052.  
  2053.                                 Defaulted Initialization     Contents
  2054. Form                            Argument List                of Slot
  2055. =======================================================================
  2056. (make-instance 'r)              (a 1 b 2)                       1
  2057. (make-instance 'r 'a 3)         (a 3 b 2)                       3
  2058. (make-instance 'r 'b 4)         (b 4 a 1)                       4
  2059. (make-instance 'r 'a 1 'a 2)    (a 1 a 2 b 2)                   1
  2060. =======================================================================
  2061.  
  2062. [change_end]
  2063.  
  2064. -------------------------------------------------------------------------------
  2065.  
  2066. 28.1.9.5. Shared-Initialize
  2067.  
  2068. [change_begin]
  2069. The generic function shared-initialize is used to fill the slots of an instance
  2070. using initialization arguments and :initform forms when an instance is created,
  2071. when an instance is re-initialized, when an instance is updated to conform to a
  2072. redefined class, and when an instance is updated to conform to a different
  2073. class. It uses standard method combination. It takes the following arguments:
  2074. the instance to be initialized, a specification of a set of names of slots
  2075. accessible in that instance, and any number of initialization arguments. The
  2076. arguments after the first two must form an initialization argument list.
  2077.  
  2078. The second argument to shared-initialize may be one of the following:
  2079.  
  2080.    *  It can be a list of slot names, which specifies the set of those slot
  2081.      names.
  2082.  
  2083.    *  It can be nil, which specifies the empty set of slot names.
  2084.  
  2085.    *  It can be the symbol t, which specifies the set of all of the slots.
  2086.  
  2087. There is a system-supplied primary method for shared-initialize whose first
  2088. parameter specializer is the class standard-object. This method behaves as
  2089. follows on each slot, whether shared or local:
  2090.  
  2091.    *  If an initialization argument in the initialization argument list
  2092.      specifies a value for that slot, that value is stored into the slot, even
  2093.      if a value has already been stored in the slot before the method is run.
  2094.      The affected slots are independent of which slots are indicated by the
  2095.      second argument to shared-initialize.
  2096.  
  2097.    *  Any slots indicated by the second argument that are still unbound at this
  2098.      point are initialized according to their :initform forms. For any such
  2099.      slot that has an :initform form, that form is evaluated in the lexical
  2100.      environment of its defining defclass form and the result is stored into
  2101.      the slot. For example, if a :before method stores a value in the slot, the
  2102.      :initform form will not be used to supply a value for the slot. If the
  2103.      second argument specifies a name that does not correspond to any slots
  2104.      accessible in the instance, the results are unspecified.
  2105.  
  2106.    *  The rules mentioned in section 28.1.9.4 are obeyed.
  2107.  
  2108. The generic function shared-initialize is called by the system-supplied primary
  2109. methods for the generic functions initialize-instance, reinitialize-instance,
  2110. update-instance-for-different-class, and update-instance-for-redefined-class.
  2111. Thus methods can be written for shared-initialize to specify actions that
  2112. should be taken in all of these contexts.
  2113. [change_end]
  2114.  
  2115. -------------------------------------------------------------------------------
  2116.  
  2117. 28.1.9.6. Initialize-Instance
  2118.  
  2119. [change_begin]
  2120. The generic function initialize-instance is called by make-instance to
  2121. initialize a newly created instance. It uses standard method combination.
  2122. Methods for initialize-instance can be defined in order to perform any
  2123. initialization that cannot be achieved with the simple slot-filling mechanisms.
  2124.  
  2125. During initialization, initialize-instance is invoked after the following
  2126. actions have been taken:
  2127.  
  2128.    *  The defaulted initialization argument list has been computed by combining
  2129.      the supplied initialization argument list with any default initialization
  2130.      arguments for the class.
  2131.  
  2132.    *  The validity of the defaulted initialization argument list has been
  2133.      checked. If any of the initialization arguments has not been declared
  2134.      valid, an error is signaled.
  2135.  
  2136.    *  A new instance whose slots are unbound has been created.
  2137.  
  2138. The generic function initialize-instance is called with the new instance and
  2139. the defaulted initialization arguments. There is a system-supplied primary
  2140. method for initialize-instance whose parameter specializer is the class
  2141. standard-object. This method calls the generic function shared-initialize to
  2142. fill in the slots according to the initialization arguments and the :initform
  2143. forms for the slots; the generic function shared-initialize is called with the
  2144. following arguments: the instance, t, and the defaulted initialization
  2145. arguments.
  2146.  
  2147. Note that initialize-instance provides the defaulted initialization argument
  2148. list in its call to shared-initialize, so the first step performed by the
  2149. system-supplied primary method for shared-initialize takes into account both
  2150. the initialization arguments provided in the call to make-instance and the
  2151. defaulted initialization argument list.
  2152.  
  2153. Methods for initialize-instance can be defined to specify actions to be taken
  2154. when an instance is initialized. If only :after methods for initialize-instance
  2155. are defined, they will be run after the system-supplied primary method for
  2156. initialization and therefore they will not interfere with the default behavior
  2157. of initialize-instance.
  2158.  
  2159. The Object System provides two functions that are useful in the bodies of
  2160. initialize-instance methods. The function slot-boundp returns a boolean value
  2161. that indicates whether a specified slot has a value; this provides a mechanism
  2162. for writing :after methods for initialize-instance that initialize slots only
  2163. if they have not already been initialized. The function slot-makunbound causes
  2164. the slot to have no value.
  2165. [change_end]
  2166.  
  2167. -------------------------------------------------------------------------------
  2168.  
  2169. 28.1.9.7. Definitions of Make-Instance and Initialize-Instance
  2170.  
  2171. [change_begin]
  2172. The generic function make-instance behaves as if it were defined as follows,
  2173. except that certain optimizations are permitted:
  2174.  
  2175. (defmethod make-instance ((class standard-class) &rest initargs)
  2176.   (setq initargs (default-initargs class initargs))
  2177.   ...
  2178.   (let ((instance (apply #'allocate-instance class initargs)))
  2179.     (apply #'initialize-instance instance initargs)
  2180.     instance))
  2181. (defmethod make-instance ((class-name symbol) &rest initargs)
  2182.   (apply #'make-instance (find-class class-name) initargs))
  2183.  
  2184. The elided code in the definition of make-instance checks the supplied
  2185. initialization arguments to determine whether an initialization argument was
  2186. supplied that neither filled a slot nor supplied an argument to an applicable
  2187. method. This check could be implemented using the generic functions
  2188. class-prototype, compute-applicable-methods, function-keywords, and
  2189. class-slot-initargs. See the third part of the Common Lisp Object System
  2190. specification for a description of this initialization argument check. [The
  2191. third part has not yet been approved by X3J13 for inclusion in the forthcoming
  2192. Common Lisp standard and is not included in this book.-GLS]
  2193.  
  2194. The generic function initialize-instance behaves as if it were defined as
  2195. follows, except that certain optimizations are permitted:
  2196.  
  2197. (defmethod initialize-instance
  2198.            ((instance standard-object) &rest initargs)
  2199.   (apply #'shared-initialize instance t initargs)))
  2200.  
  2201. These procedures can be customized at either the Programmer Interface level,
  2202. the meta-object level, or both.
  2203.  
  2204. Customizing at the Programmer Interface level includes using the :initform,
  2205. :initarg, and :default-initargs options to defclass, as well as defining
  2206. methods for make-instance and initialize-instance. It is also possible to
  2207. define methods for shared-initialize, which would be invoked by the generic
  2208. functions reinitialize-instance, update-instance-for-redefined-class,
  2209. update-instance-for-different-class, and initialize-instance. The meta-object
  2210. level supports additional customization by allowing methods to be defined on
  2211. make-instance, default-initargs, and allocate-instance. Parts 2 and 3 of the
  2212. Common Lisp Object System specification document each of these generic
  2213. functions and the system-supplied primary methods. [The third part has not yet
  2214. been approved by X3J13 for inclusion in the forthcoming Common Lisp standard
  2215. and is not included in this book.-GLS]
  2216.  
  2217. Implementations are permitted to make certain optimizations to
  2218. initialize-instance and shared-initialize. The description of shared-initialize
  2219. in section 28.2 mentions the possible optimizations.
  2220.  
  2221. Because of optimization, the check for valid initialization arguments might not
  2222. be implemented using the generic functions class-prototype,
  2223. compute-applicable-methods, function-keywords, and class-slot-initargs. In
  2224. addition, methods for the generic function default-initargs and the
  2225. system-supplied primary methods for allocate-instance, initialize-instance, and
  2226. shared-initialize might not be called on every call to make-instance or might
  2227. not receive exactly the arguments that would be expected.
  2228. [change_end]
  2229.  
  2230. -------------------------------------------------------------------------------
  2231.  
  2232. 28.1.10. Redefining Classes
  2233.  
  2234. [change_begin]
  2235. A class that is an instance of standard-class can be redefined if the new class
  2236. will also be an instance of standard-class. Redefining a class modifies the
  2237. existing class object to reflect the new class definition; it does not create a
  2238. new class object for the class. Any method object created by a :reader,
  2239. :writer, or :accessor option specified by the old defclass form is removed from
  2240. the corresponding generic function. Methods specified by the new defclass form
  2241. are added.
  2242.  
  2243. When the class C is redefined, changes are propagated to its instances and to
  2244. instances of any of its subclasses. Updating such an instance occurs at an
  2245. implementation-dependent time, but no later than the next time a slot of that
  2246. instance is read or written. Updating an instance does not change its identity
  2247. as defined by the eq function. The updating process may change the slots of
  2248. that particular instance, but it does not create a new instance. Whether
  2249. updating an instance consumes storage is implementation-dependent.
  2250.  
  2251. Note that redefining a class may cause slots to be added or deleted. If a class
  2252. is redefined in a way that changes the set of local slots accessible in
  2253. instances, the instances will be updated. It is implementation-dependent
  2254. whether instances are updated if a class is redefined in a way that does not
  2255. change the set of local slots accessible in instances.
  2256.  
  2257. The value of a slot that is specified as shared both in the old class and in
  2258. the new class is retained. If such a shared slot was unbound in the old class,
  2259. it will be unbound in the new class. Slots that were local in the old class and
  2260. that are shared in the new class are initialized. Newly added shared slots are
  2261. initialized.
  2262.  
  2263. Each newly added shared slot is set to the result of evaluating the captured
  2264. :initform form for the slot that was specified in the defclass form for the new
  2265. class. If there is no :initform form, the slot is unbound.
  2266.  
  2267. If a class is redefined in such a way that the set of local slots accessible in
  2268. an instance of the class is changed, a two-step process of updating the
  2269. instances of the class takes place. The process may be explicitly started by
  2270. invoking the generic function make-instances-obsolete. This two-step process
  2271. can happen in other circumstances in some implementations. For example, in some
  2272. implementations this two-step process will be triggered if the order of slots
  2273. in storage is changed.
  2274.  
  2275. The first step modifies the structure of the instance by adding new local slots
  2276. and discarding local slots that are not defined in the new version of the
  2277. class. The second step initializes the newly added local slots and performs any
  2278. other user-defined actions. These steps are further specified in the next two
  2279. sections.
  2280. [change_end]
  2281.  
  2282. -------------------------------------------------------------------------------
  2283.  
  2284.    *  Modifying the Structure of Instances
  2285.    *  Initializing Newly Added Local Slots
  2286.    *  Customizing Class Redefinition
  2287.    *  Extensions
  2288.  
  2289. -------------------------------------------------------------------------------
  2290.  
  2291. 28.1.10.1. Modifying the Structure of Instances
  2292.  
  2293. [change_begin]
  2294. The first step modifies the structure of instances of the redefined class to
  2295. conform to its new class definition. Local slots specified by the new class
  2296. definition that are not specified as either local or shared by the old class
  2297. are added, and slots not specified as either local or shared by the new class
  2298. definition that are specified as local by the old class are discarded. The
  2299. names of these added and discarded slots are passed as arguments to
  2300. update-instance-for-redefined-class as described in the next section.
  2301.  
  2302. The values of local slots specified by both the new and old classes are
  2303. retained. If such a local slot was unbound, it remains unbound.
  2304.  
  2305. The value of a slot that is specified as shared in the old class and as local
  2306. in the new class is retained. If such a shared slot was unbound, the local slot
  2307. will be unbound.
  2308. [change_end]
  2309.  
  2310. -------------------------------------------------------------------------------
  2311.  
  2312. 28.1.10.2. Initializing Newly Added Local Slots
  2313.  
  2314. [change_begin]
  2315. The second step initializes the newly added local slots and performs any other
  2316. user-defined actions. This step is implemented by the generic function
  2317. update-instance-for-redefined-class, which is called after completion of the
  2318. first step of modifying the structure of the instance.
  2319.  
  2320. The generic function update-instance-for-redefined-class takes four required
  2321. arguments: the instance being updated after it has undergone the first step, a
  2322. list of the names of local slots that were added, a list of the names of local
  2323. slots that were discarded, and a property list containing the slot names and
  2324. values of slots that were discarded and had values. Included among the
  2325. discarded slots are slots that were local in the old class and that are shared
  2326. in the new class.
  2327.  
  2328. The generic function update-instance-for-redefined-class also takes any number
  2329. of initialization arguments. When it is called by the system to update an
  2330. instance whose class has been redefined, no initialization arguments are
  2331. provided.
  2332.  
  2333. There is a system-supplied primary method for the generic function
  2334. update-instance-for-redefined-class whose parameter specializer for its
  2335. instance argument is the class standard-object. First this method checks the
  2336. validity of initialization arguments and signals an error if an initialization
  2337. argument is supplied that is not declared valid (see section 28.1.9.2.) Then it
  2338. calls the generic function shared-initialize with the following arguments: the
  2339. instance, the list of names of the newly added slots, and the initialization
  2340. arguments it received.
  2341. [change_end]
  2342.  
  2343. -------------------------------------------------------------------------------
  2344.  
  2345. 28.1.10.3. Customizing Class Redefinition
  2346.  
  2347. [change_begin]
  2348. Methods for update-instance-for-redefined-class may be defined to specify
  2349. actions to be taken when an instance is updated. If only :after methods for
  2350. update-instance-for-redefined-class are defined, they will be run after the
  2351. system-supplied primary method for initialization and therefore will not
  2352. interfere with the default behavior of update-instance-for-redefined-class.
  2353. Because no initialization arguments are passed to
  2354. update-instance-for-redefined-class when it is called by the system, the
  2355. :initform forms for slots that are filled by :before methods for
  2356. update-instance-for-redefined-class will not be evaluated by shared-initialize.
  2357.  
  2358. Methods for shared-initialize may be defined to customize class redefinition
  2359. (see section 28.1.9.5).
  2360. [change_end]
  2361.  
  2362. -------------------------------------------------------------------------------
  2363.  
  2364. 28.1.10.4. Extensions
  2365.  
  2366. [change_begin]
  2367. There are two allowed extensions to class redefinition:
  2368.  
  2369.    *  The Object System may be extended to permit the new class to be an
  2370.      instance of a metaclass other than the metaclass of the old class.
  2371.  
  2372.    *  The Object System may be extended to support an updating process when
  2373.      either the old or the new class is an instance of a class other than
  2374.      standard-class that is not a built-in class.
  2375.  
  2376. [change_end]
  2377.  
  2378. -------------------------------------------------------------------------------
  2379.  
  2380. 28.1.11. Changing the Class of an Instance
  2381.  
  2382. [change_begin]
  2383. The function change-class can be used to change the class of an instance from
  2384. its current class,   , to a different class,   ; it changes the structure of
  2385. the instance to conform to the definition of the class   .
  2386.  
  2387. Note that changing the class of an instance may cause slots to be added or
  2388. deleted.
  2389.  
  2390. When change-class is invoked on an instance, a two-step updating process takes
  2391. place. The first step modifies the structure of the instance by adding new
  2392. local slots and discarding local slots that are not specified in the new
  2393. version of the instance. The second step initializes the newly added local
  2394. slots and performs any other user-defined actions. These steps are further
  2395. described in the following two sections.
  2396. [change_end]
  2397.  
  2398. -------------------------------------------------------------------------------
  2399.  
  2400.    *  Modifying the Structure of an Instance
  2401.    *  Initializing Newly Added Local Slots
  2402.    *  Customizing the Change of Class of an Instance
  2403.  
  2404. -------------------------------------------------------------------------------
  2405.  
  2406. 28.1.11.1. Modifying the Structure of an Instance
  2407.  
  2408. [change_begin]
  2409. In order to make an instance conform to the class   , local slots specified by
  2410. the class    that are not specified by the class    are added, and local slots
  2411. not specified by the class    that are specified by the class    are discarded.
  2412.  
  2413. The values of local slots specified by both the class    and the class    are
  2414. retained. If such a local slot was unbound, it remains unbound.
  2415.  
  2416. The values of slots specified as shared in the class    and as local in the
  2417. class    are retained.
  2418.  
  2419. This first step of the update does not affect the values of any shared slots.
  2420. [change_end]
  2421.  
  2422. -------------------------------------------------------------------------------
  2423.  
  2424. 28.1.11.2. Initializing Newly Added Local Slots
  2425.  
  2426. [change_begin]
  2427. The second step of the update initializes the newly added slots and performs
  2428. any other user-defined actions. This step is implemented by the generic
  2429. function update-instance-for-different-class. The generic function
  2430. update-instance-for-different-class is invoked by change-class after the first
  2431. step of the update has been completed.
  2432.  
  2433. The generic function update-instance-for-different-class is invoked on two
  2434. arguments computed by change-class. The first argument passed is a copy of the
  2435. instance being updated and is an instance of the class   ; this copy has
  2436. dynamic extent within the generic function change-class. The second argument is
  2437. the instance as updated so far by change-class and is an instance of the class
  2438.   .
  2439.  
  2440. The generic function update-instance-for-different-class also takes any number
  2441. of initialization arguments. When it is called by change-class, no
  2442. initialization arguments are provided.
  2443.  
  2444. There is a system-supplied primary method for the generic function
  2445. update-instance-for-different-class that has two parameter specializers, each
  2446. of which is the class standard-object. First this method checks the validity of
  2447. initialization arguments and signals an error if an initialization argument is
  2448. supplied that is not declared valid (see section 28.1.9.2). Then it calls the
  2449. generic function shared-initialize with the following arguments: the instance,
  2450. a list of names of the newly added slots, and the initialization arguments it
  2451. received.
  2452. [change_end]
  2453.  
  2454. -------------------------------------------------------------------------------
  2455.  
  2456. 28.1.11.3. Customizing the Change of Class of an Instance
  2457.  
  2458. [change_begin]
  2459. Methods for update-instance-for-different-class may be defined to specify
  2460. actions to be taken when an instance is updated. If only :after methods for
  2461. update-instance-for-different-class are defined, they will be run after the
  2462. system-supplied primary method for initialization and will not interfere with
  2463. the default behavior of update-instance-for-different-class. Because no
  2464. initialization arguments are passed to update-instance-for-different-class when
  2465. it is called by change-class, the :initform forms for slots that are filled by
  2466. :before methods for update-instance-for-different-class will not be evaluated
  2467. by shared-initialize.
  2468.  
  2469. Methods for shared-initialize may be defined to customize class redefinition
  2470. (see section 28.1.9.5).
  2471. [change_end]
  2472.  
  2473. -------------------------------------------------------------------------------
  2474.  
  2475. 28.1.12. Reinitializing an Instance
  2476.  
  2477. [change_begin]
  2478. The generic function reinitialize-instance may be used to change the values of
  2479. slots according to initialization arguments.
  2480.  
  2481. The process of reinitialization changes the values of some slots and performs
  2482. any user-defined actions.
  2483.  
  2484. Reinitialization does not modify the structure of an instance to add or delete
  2485. slots, and it does not use any :initform forms to initialize slots.
  2486.  
  2487. The generic function reinitialize-instance may be called directly. It takes one
  2488. required argument, the instance. It also takes any number of initialization
  2489. arguments to be used by methods for reinitialize-instance or for
  2490. shared-initialize. The arguments after the required instance must form an
  2491. initialization argument list.
  2492.  
  2493. There is a system-supplied primary method for reinitialize-instance whose
  2494. parameter specializer is the class standard-object. First this method checks
  2495. the validity of initialization arguments and signals an error if an
  2496. initialization argument is supplied that is not declared valid (see section
  2497. 28.1.9.2). Then it calls the generic function shared-initialize with the
  2498. following arguments: the instance, nil, and the initialization arguments it
  2499. received.
  2500. [change_end]
  2501.  
  2502. -------------------------------------------------------------------------------
  2503.  
  2504.    *  Customizing Reinitialization
  2505.  
  2506. -------------------------------------------------------------------------------
  2507.  
  2508. 28.1.12.1. Customizing Reinitialization
  2509.  
  2510. [change_begin]
  2511. Methods for the generic function reinitialize-instance may be defined to
  2512. specify actions to be taken when an instance is updated. If only :after methods
  2513. for reinitialize-instance are defined, they will be run after the
  2514. system-supplied primary method for initialization and therefore will not
  2515. interfere with the default behavior of reinitialize-instance.
  2516.  
  2517. Methods for shared-initialize may be defined to customize class redefinition
  2518. (see section 28.1.9.5).
  2519. [change_end]
  2520.  
  2521. -------------------------------------------------------------------------------
  2522.  
  2523.  
  2524. 28.2. Functions in the Programmer Interface
  2525.  
  2526. [change_begin]
  2527. This section describes the functions, macros, special forms, and generic
  2528. functions provided by the Common Lisp Object System Programmer Interface. The
  2529. Programmer Interface comprises the functions and macros that are sufficient for
  2530. writing most object-oriented programs.
  2531.  
  2532. This section is reference material that requires an understanding of the basic
  2533. concepts of the Common Lisp Object System. The functions are arranged in
  2534. alphabetical order for convenient reference.
  2535.  
  2536. The description of each function, macro, special form, and generic function
  2537. includes its purpose, its syntax, the semantics of its arguments and returned
  2538. values, and often an example and cross-references to related functions.
  2539.  
  2540. The syntax description for a function, macro, or special form describes its
  2541. parameters. The description of a generic function includes descriptions of the
  2542. methods that are defined on that generic function by the Common Lisp Object
  2543. System. A method signature is used to describe the parameters and parameter
  2544. specializers for each method.
  2545.  
  2546. The following is an example of the format for the syntax description of a
  2547. generic function with the method signature for one primary method:
  2548.  
  2549. [Generic function]
  2550. f x y &optional z &key :k
  2551. [Primary method]
  2552. f (x class) (y t) &optional z &key :k
  2553.  
  2554. This description indicates that the generic function f has two required
  2555. parameters, x and y. In addition, there is an optional parameter z and a
  2556. keyword parameter :k.
  2557.  
  2558. The method signature indicates that this method on the generic function f has
  2559. two required parameters, x, which must be an instance of the class class, and
  2560. y, which can be any object. In addition, there is an optional parameter z and a
  2561. keyword parameter :k. The signature also indicates that this method on f is a
  2562. primary method and has no qualifiers.
  2563.  
  2564. The syntax description for a generic function describes the lambda-list of the
  2565. generic function itself, while the method signatures describe the lambda-lists
  2566. of the defined methods.
  2567.  
  2568. The generic functions described in this book are all standard generic
  2569. functions. They all use standard method combination.
  2570.  
  2571. Any implementation of the Common Lisp Object System is allowed to provide
  2572. additional methods on the generic functions described here.
  2573.  
  2574. It is useful to categorize the functions and macros according to their role in
  2575. this standard:
  2576.  
  2577.    *  Tools used for simple object-oriented programming
  2578.  
  2579.      These tools allow for defining new classes, methods, and generic functions
  2580.      and for making instances. Some tools used within method bodies are also
  2581.      listed here. Some of the macros listed here have a corresponding function
  2582.      that performs the same task at a lower level of abstraction.
  2583.  
  2584.      call-next-method                initialize-instance
  2585.      change-class                    make-instance
  2586.      defclass                        next-method-p
  2587.      defgeneric                      slot-boundp
  2588.      defmethod                       slot-value
  2589.      generic-flet                    with-accessors
  2590.      generic-function                with-added-methods
  2591.      generic-labels                  with-slots
  2592.  
  2593.    *  Functions underlying the commonly used macros
  2594.  
  2595.      add-method                      reinitialize-instance
  2596.      class-name                      remove-method
  2597.      compute-applicable-methods      shared-initialize
  2598.      ensure-generic-function         slot-exists-p
  2599.      find-class                      slot-makunbound
  2600.      find-method                     slot-missing
  2601.      function-keywords               slot-unbound
  2602.      make-instances-obsolete         update-instance-for-different-class
  2603.      no-applicable-method            update-instance-for-redefined-class
  2604.      no-next-method
  2605.  
  2606.    *  Tools for declarative method combination
  2607.  
  2608.      call-method                     method-combination-error
  2609.      define-method-combination       method-qualifiers
  2610.      invalid-method-error
  2611.  
  2612.    *  General Common Lisp support tools
  2613.  
  2614.      class-of                        print-object
  2615.      documentation                   symbol-macrolet
  2616.  
  2617.      [Note that describe appeared in this list in the original CLOS proposal
  2618.      [5,7], but X3J13 voted in March 1989 (DESCRIBE-UNDERSPECIFIED)   not to
  2619.      make describe a generic function after all (see describe-object).-GLS]
  2620.  
  2621. [At this point the original CLOS report contained a description of the [[ and
  2622. ]] notation; that description is omitted here. I have adopted the notation for
  2623. use throughout this book. It is described in section 1.2.5.-GLS]
  2624.  
  2625. [Generic function]
  2626. add-method generic-function method
  2627. [Primary method]
  2628.  
  2629. add-method
  2630.    (generic-function standard-generic-function) (method method)
  2631.  
  2632. The generic function add-method adds a method to a generic function. It
  2633. destructively modifies the generic function and returns the modified generic
  2634. function as its result.
  2635.  
  2636. The generic-function argument is a generic function object.
  2637.  
  2638. The method argument is a method object. The lambda-list of the method function
  2639. must be congruent with the lambda-list of the generic function, or an error is
  2640. signaled.
  2641.  
  2642. The modified generic function is returned. The result of add-method is eq to
  2643. the generic-function argument.
  2644.  
  2645. If the given method agrees with an existing method of the generic function on
  2646. parameter specializers and qualifiers, the existing method is replaced. See
  2647. section 28.1.6.3 for a definition of agreement in this context.
  2648.  
  2649. If the method object is a method object of another generic function, an error
  2650. is signaled.
  2651.  
  2652. See section 28.1.6.3 as well as defmethod, defgeneric, find-method, and
  2653. remove-method.
  2654.  
  2655. [Macro]
  2656. call-method method next-method-list
  2657.  
  2658. The macro call-method is used in method combination. This macro hides the
  2659. implementation-dependent details of how methods are called. It can be used only
  2660. within an effective method form, for the name call-method is defined only
  2661. within the lexical scope of such a form.
  2662.  
  2663. The macro call-method invokes the specified method, supplying it with arguments
  2664. and with definitions for call-next-method and for next-method-p. The arguments
  2665. are the arguments that were supplied to the effective method form containing
  2666. the invocation of call-method. The definitions of call-next-method and
  2667. next-method-p rely on the list of method objects given as the second argument
  2668. to call-method.
  2669.  
  2670. The call-next-method function available to the method that is the first subform
  2671. will call the first method in the list that is the second subform. The
  2672. call-next-method function available in that method, in turn, will call the
  2673. second method in the list that is the second subform, and so on, until the list
  2674. of next methods is exhausted.
  2675.  
  2676. The method argument is a method object; the next-method-list argument is a list
  2677. of method objects.
  2678.  
  2679. A list whose first element is the symbol make-method and whose second element
  2680. is a Lisp form can be used instead of a method object as the first subform of
  2681. call-method or as an element of the second subform of call-method. Such a list
  2682. specifies a method object whose method function has a body that is the given
  2683. form.
  2684.  
  2685. The result of call-method is the value or values returned by the method
  2686. invocation.
  2687.  
  2688. See call-next-method, define-method-combination, and next-method-p.
  2689.  
  2690. [Function]
  2691. call-next-method &rest args
  2692.  
  2693. The function call-next-method can be used within the body of a method defined
  2694. by a method-defining form to call the next method.
  2695.  
  2696. The function call-next-method returns the value or values returned by the
  2697. method it calls. If there is no next method, the generic function
  2698. no-next-method is called.
  2699.  
  2700. The type of method combination used determines which methods can invoke
  2701. call-next-method. The standard method combination type allows call-next-method
  2702. to be used within primary methods and :around methods.
  2703.  
  2704. The standard method combination type defines the next method according to the
  2705. following rules:
  2706.  
  2707.    *  If call-next-method is used in an :around method, the next method is the
  2708.      next most specific :around method, if one is applicable.
  2709.  
  2710.    *  If there are no :around methods at all or if call-next-method is called
  2711.      by the least specific :around method, other methods are called as follows:
  2712.  
  2713.         o  All the :before methods are called, in most-specific-first order.
  2714.           The function call-next-method cannot be used in :before methods.
  2715.  
  2716.         o  The most specific primary method is called. Inside the body of a
  2717.           primary method, call-next-method may be used to pass control to the
  2718.           next most specific primary method. The generic function
  2719.           no-next-method is called if call-next-method is used and there are no
  2720.           more primary methods.
  2721.  
  2722.         o  All the :after methods are called in most-specific-last order. The
  2723.           function call-next-method cannot be used in :after methods.
  2724.  
  2725. For further discussion of the use of call-next-method, see sections 28.1.7.2
  2726. and 28.1.7.4.
  2727.  
  2728. When call-next-method is called with no arguments, it passes the current
  2729. method's original arguments to the next method. Neither argument defaulting,
  2730. nor using setq, nor rebinding variables with the same names as parameters of
  2731. the method affects the values call-next-method passes to the method it calls.
  2732.  
  2733. When call-next-method is called with arguments, the next method is called with
  2734. those arguments. When providing arguments to call-next-method, the following
  2735. rule must be satisfied or an error is signaled: The ordered set of methods
  2736. applicable for a changed set of arguments for call-next-method must be the same
  2737. as the ordered set of applicable methods for the original arguments to the
  2738. generic function. Optimizations of the error checking are possible, but they
  2739. must not change the semantics of call-next-method.
  2740.  
  2741. If call-next-method is called with arguments but omits optional arguments, the
  2742. next method called defaults those arguments.
  2743.  
  2744. The function call-next-method returns the value or values returned by the
  2745. method it calls.
  2746.  
  2747. Further computation is possible after call-next-method returns.
  2748.  
  2749. The definition of the function call-next-method has lexical scope (for it is
  2750. defined only within the body of a method defined by a method-defining form) and
  2751. indefinite extent.
  2752.  
  2753. For generic functions using a type of method combination defined by the short
  2754. form of define-method-combination, call-next-method can be used in :around
  2755. methods only.
  2756.  
  2757. The function next-method-p can be used to test whether or not there is a next
  2758. method.
  2759.  
  2760. If call-next-method is used in methods that do not support it, an error is
  2761. signaled.
  2762.  
  2763. See sections 28.1.7, 28.1.7.2, and 28.1.7.4 as well as the functions
  2764. define-method-combination, next-method-p, and no-next-method.
  2765.  
  2766. [Generic function]
  2767.  
  2768. change-class instance new-class
  2769.  
  2770. [Primary method]
  2771.  
  2772. change-class (instance standard-object)
  2773.              (new-class standard-class)
  2774. change-class (instance t)
  2775.              (new-class symbol)
  2776.  
  2777. The generic function change-class changes the class of an instance to a new
  2778. class. It destructively modifies and returns the instance.
  2779.  
  2780. If in the old class there is any slot of the same name as a local slot in the
  2781. new class, the value of that slot is retained. This means that if the slot has
  2782. a value, the value returned by slot-value after change-class is invoked is eql
  2783. to the value returned by slot-value before change-class is invoked. Similarly,
  2784. if the slot was unbound, it remains unbound. The other slots are initialized as
  2785. described in section 28.1.11.
  2786.  
  2787. The instance argument is a Lisp object.
  2788.  
  2789. The new-class argument is a class object or a symbol that names a class.
  2790.  
  2791. If the second of the preceding methods is selected, that method invokes
  2792. change-class on instance and (find-class new-class).
  2793.  
  2794. The modified instance is returned. The result of change-class is eq to the
  2795. instance argument.
  2796.  
  2797. Examples:
  2798.  
  2799. (defclass position () ())
  2800.  
  2801. (defclass x-y-position (position)
  2802.   ((x :initform 0 :initarg :x)
  2803.    (y :initform 0 :initarg :y)))
  2804.  
  2805. (defclass rho-theta-position (position)
  2806.   ((rho :initform 0)
  2807.    (theta :initform 0)))
  2808.  
  2809. (defmethod update-instance-for-different-class :before
  2810.            ((old x-y-position)
  2811.             (new rho-theta-position)
  2812.             &key)
  2813.   ;; Copy the position information from old to new to make new
  2814.   ;; be a rho-theta-position at the same position as old.
  2815.   (let ((x (slot-value old 'x))
  2816.         (y (slot-value old 'y)))
  2817.     (setf (slot-value new 'rho) (sqrt (+ (* x x) (* y y)))
  2818.           (slot-value new 'theta) (atan y x))))
  2819.  
  2820. ;;; At this point an instance of the class x-y-position can be
  2821. ;;; changed to be an instance of the class rho-theta-position
  2822. ;;; using change-class:
  2823.  
  2824. (setq p1 (make-instance 'x-y-position :x 2 :y 0))
  2825.  
  2826. (change-class p1 'rho-theta-position)
  2827.  
  2828. ;;; The result is that the instance bound to p1 is now
  2829. ;;; an instance of the class rho-theta-position.
  2830. ;;; The update-instance-for-different-class method
  2831. ;;; performed the initialization of the rho and theta
  2832. ;;; slots based on the values of the x and y slots,
  2833. ;;; which were maintained by the old instance.
  2834.  
  2835. After completing all other actions, change-class invokes the generic function
  2836. update-instance-for-different-class. The generic function
  2837. update-instance-for-different-class can be used to assign values to slots in
  2838. the transformed instance.
  2839.  
  2840. The generic function change-class has several semantic difficulties. First, it
  2841. performs a destructive operation that can be invoked within a method on an
  2842. instance that was used to select that method. When multiple methods are
  2843. involved because methods are being combined, the methods currently executing or
  2844. about to be executed may no longer be applicable. Second, some implementations
  2845. might use compiler optimizations of slot access, and when the class of an
  2846. instance is changed the assumptions the compiler made might be violated. This
  2847. implies that a programmer must not use change-class inside a method if any
  2848. methods for that generic function access any slots, or the results are
  2849. undefined.
  2850.  
  2851. See section 28.1.11 as well as update-instance-for-different-class.
  2852.  
  2853. [Generic function]
  2854. class-name class
  2855.  
  2856. [Primary method]
  2857. class-name (class class)
  2858.  
  2859. The generic function class-name takes a class object and returns its name. The
  2860. class argument is a class object. The new-value argument is any object. The
  2861. name of the given class is returned.
  2862.  
  2863. The name of an anonymous class is nil.
  2864.  
  2865. If S is a symbol such that S =(class-name C) and C = (find-class S), then S is
  2866. the proper name of C (see section 28.1.2).
  2867.  
  2868. See also section 28.1.2 and find-class.
  2869.  
  2870. [Generic function]
  2871. (setf class-name) new-value class
  2872.  
  2873. [Primary method]
  2874. (setf class-name) new-value (class class)
  2875.  
  2876. The generic function (setf class-name) takes a class object and sets its name.
  2877. The class argument is a class object. The new-value argument is any object.
  2878.  
  2879. [Function]
  2880. class-of object
  2881.  
  2882. The function class-of returns the class of which the given object is an
  2883. instance. The argument to class-of may be any Common Lisp object. The function
  2884. class-of returns the class of which the argument is an instance.
  2885.  
  2886. [Function]
  2887. compute-applicable-methods generic-function function-arguments
  2888.  
  2889. Given a generic function and a set of arguments, the function
  2890. compute-applicable-methods returns the set of methods that are applicable for
  2891. those arguments.
  2892.  
  2893. The methods are sorted according to precedence order. See section 28.1.7.
  2894.  
  2895. The generic-function argument must be a generic function object. The
  2896. function-arguments argument is a list of the arguments to that generic
  2897. function. The result is a list of the applicable methods in order of
  2898. precedence. See section 28.1.7.
  2899.  
  2900. [Macro]
  2901.  
  2902. defclass class-name ({superclass-name}*)
  2903.          ({slot-specifier}*) [[?class-option]]
  2904.  
  2905. class-name ::= symbol
  2906. superclass-name ::= symbol
  2907. slot-specifier ::= slot-name | (slot-name [[?slot-option]])
  2908. slot-name ::= symbol
  2909. slot-option ::= {:reader reader-function-name}*
  2910.                 | {:writer writer-function-name}*
  2911.                 | {:accessor reader-function-name}*
  2912.                 | {:allocation allocation-type}*
  2913.                 | {:initarg initarg-name}*
  2914.                 | {:initform form}*
  2915.                 | {:type type-specifier}*
  2916.                 | {:documentation string}*
  2917.  
  2918. reader-function-name ::= symbol
  2919. writer-function-name ::= function-name/
  2920. function-name ::= {symbol | (setf symbol)}
  2921. initarg-name ::= symbol
  2922. allocation-type ::= :instance | :class
  2923. class-option ::= (:default-initargs initarg-list)
  2924.                 | (:documentation string)
  2925.                 | (:metaclass class-name)
  2926. initarg-list ::= {initarg-name default-initial-value-form}*
  2927.  
  2928. The macro defclass defines a new named class. It returns the new class object
  2929. as its result.
  2930.  
  2931. The syntax of defclass provides options for specifying initialization arguments
  2932. for slots, for specifying default initialization values for slots, and for
  2933. requesting that methods on specified generic functions be automatically
  2934. generated for reading and writing the values of slots. No reader or writer
  2935. functions are defined by default; their generation must be explicitly
  2936. requested.
  2937.  
  2938. Defining a new class also causes a type of the same name to be defined. The
  2939. predicate (typep object class-name) returns true if the class of the given
  2940. object is class-name itself or a subclass of the class class-name. A class
  2941. object can be used as a type specifier. Thus (typep object class) returns true
  2942. if the class of the object is class itself or a subclass of class.
  2943.  
  2944. The class-name argument is a non-nil symbol. It becomes the proper name of the
  2945. new class. If a class with the same proper name already exists and that class
  2946. is an instance of standard-class, and if the defclass form for the definition
  2947. of the new class specifies a class of class standard-class, the definition of
  2948. the existing class is replaced.
  2949.  
  2950. Each superclass-name argument is a non-nil symbol that specifies a direct
  2951. superclass of the new class. The new class will inherit slots and methods from
  2952. each of its direct superclasses, from their direct superclasses, and so on. See
  2953. section 28.1.3 for a discussion of how slots and methods are inherited.
  2954.  
  2955. Each slot-specifier argument is the name of the slot or a list consisting of
  2956. the slot name followed by zero or more slot options. The slot-name argument is
  2957. a symbol that is syntactically valid for use as a variable name. If there are
  2958. any duplicate slot names, an error is signaled.
  2959.  
  2960. The following slot options are available:
  2961.  
  2962.    *  The :reader slot option specifies that an unqualified method is to be
  2963.      defined on the generic function named reader-function-name to read the
  2964.      value of the given slot. The reader-function-name argument is a non-nil
  2965.      symbol. The :reader slot option may be specified more than once for a
  2966.      given slot.
  2967.  
  2968.    *  The :writer slot option specifies that an unqualified method is to be
  2969.      defined on the generic function named writer-function-name to write the
  2970.      value of the slot. The writer-function-name argument is a function-name.
  2971.      The :writer slot option may be specified more than once for a given slot.
  2972.  
  2973.    *  The :accessor slot option specifies that an unqualified method is to be
  2974.      defined on the generic function named reader-function-name to read the
  2975.      value of the given slot and that an unqualified method is to be defined on
  2976.      the generic function named (setf reader-function-name) to be used with
  2977.      setf to modify the value of the slot. The reader-function-name argument is
  2978.      a non-nil symbol. The :accessor slot option may be specified more than
  2979.      once for a given slot.
  2980.  
  2981.    *  The :allocation slot option is used to specify where storage is to be
  2982.      allocated for the given slot. Storage for a slot may be located in each
  2983.      instance or in the class object itself, for example. The value of the
  2984.      allocation-type argument can be either the keyword :instance or the
  2985.      keyword :class. The :allocation slot option may be specified at most once
  2986.      for a given slot. If the :allocation slot option is not specified, the
  2987.      effect is the same as specifying :allocation :instance.
  2988.  
  2989.         o  If allocation-type is :instance, a local slot of the given name is
  2990.           allocated in each instance of the class.
  2991.  
  2992.         o  If allocation-type is :class, a shared slot of the given name is
  2993.           allocated. The value of the slot is shared by all instances of the
  2994.           class. If a class C defines such a shared slot, any subclass C of C
  2995.           will share this single slot unless the defclass form for C specifies
  2996.           a slot of the same name or there is a superclass of C that precedes C
  2997.           in the class precedence list of C and that defines a slot of the same
  2998.           name.
  2999.  
  3000.    *  The :initform slot option is used to provide a default initial value form
  3001.      to be used in the initialization of the slot. The :initform slot option
  3002.      may be specified at most once for a given slot. This form is evaluated
  3003.      every time it is used to initialize the slot. The lexical environment in
  3004.      which this form is evaluated is the lexical environment in which the
  3005.      defclass form was evaluated. Note that the lexical environment refers both
  3006.      to variables and to functions. For local slots, the dynamic environment is
  3007.      the dynamic environment in which make-instance was called; for shared
  3008.      slots, the dynamic environment is the dynamic environment in which the
  3009.      defclass form was evaluated. See section 28.1.9.
  3010.  
  3011.      No implementation is permitted to extend the syntax of defclass to allow
  3012.      (slot-name form) as an abbreviation for (slot-name :initform form).
  3013.  
  3014.    *  The :initarg slot option declares an initialization argument named
  3015.      initarg-name and specifies that this initialization argument initializes
  3016.      the given slot. If the initialization argument has a value in the call to
  3017.      initialize-instance, the value will be stored into the given slot, and the
  3018.      slot's :initform slot option, if any, is not evaluated. If none of the
  3019.      initialization arguments specified for a given slot has a value, the slot
  3020.      is initialized according to the :initform slot option, if specified. The
  3021.      :initarg slot option can be specified more than once for a given slot. The
  3022.      initarg-name argument can be any symbol.
  3023.  
  3024.    *  The :type slot option specifies that the contents of the slot will always
  3025.      be of the specified data type. It effectively declares the result type of
  3026.      the reader generic function when applied to an object of this class. The
  3027.      result of attempting to store in a slot a value that does not satisfy the
  3028.      type of the slot is undefined. The :type slot option may be specified at
  3029.      most once for a given slot. The :type slot option is further discussed in
  3030.      section 28.1.3.2.
  3031.  
  3032.    *  The :documentation slot option provides a documentation string for the
  3033.      slot.
  3034.  
  3035. Each class option is an option that refers to the class as a whole or to all
  3036. class slots. The following class options are available:
  3037.  
  3038.    *  The :default-initargs class option is followed by a list of alternating
  3039.      initialization argument names and default initial value forms. If any of
  3040.      these initialization arguments does not appear in the initialization
  3041.      argument list supplied to make-instance, the corresponding default initial
  3042.      value form is evaluated, and the initialization argument name and the
  3043.      form's value are added to the end of the initialization argument list
  3044.      before the instance is created (see section 28.1.9). The default initial
  3045.      value form is evaluated each time it is used. The lexical environment in
  3046.      which this form is evaluated is the lexical environment in which the
  3047.      defclass form was evaluated. The dynamic environment is the dynamic
  3048.      environment in which make-instance was called. If an initialization
  3049.      argument name appears more than once in a :default-initargs class option,
  3050.      an error is signaled. The :default-initargs class option may be specified
  3051.      at most once.
  3052.  
  3053.    *  The :documentation class option causes a documentation string to be
  3054.      attached to the class name. The documentation type for this string is
  3055.      type. The form (documentation class-name 'type) may be used to retrieve
  3056.      the documentation string. The :documentation class option may be specified
  3057.      at most once.
  3058.  
  3059.    *  The :metaclass class option is used to specify that instances of the
  3060.      class being defined are to have a different metaclass than the default
  3061.      provided by the system (the class standard-class). The class-name argument
  3062.      is the name of the desired metaclass. The :metaclass class option may be
  3063.      specified at most once.
  3064.  
  3065. The new class object is returned as the result.
  3066.  
  3067. If a class with the same proper name already exists and that class is an
  3068. instance of standard-class, and if the defclass form for the definition of the
  3069. new class specifies a class of class standard-class, the existing class is
  3070. redefined, and instances of it (and its subclasses) are updated to the new
  3071. definition at the time that they are next accessed (see section 28.1.10).
  3072.  
  3073. Note the following rules of defclass for standard classes:
  3074.  
  3075.    *  It is not required that the superclasses of a class be defined before the
  3076.      defclass form for that class is evaluated.
  3077.  
  3078.    *  All the superclasses of a class must be defined before an instance of the
  3079.      class can be made.
  3080.  
  3081.    *  A class must be defined before it can be used as a parameter specializer
  3082.      in a defmethod form.
  3083.  
  3084. The Object System may be extended to cover situations where these rules are not
  3085. obeyed.
  3086.  
  3087. Some slot options are inherited by a class from its superclasses, and some can
  3088. be shadowed or altered by providing a local slot description. No class options
  3089. except :default-initargs are inherited. For a detailed description of how slots
  3090. and slot options are inherited, see section 28.1.3.2.
  3091.  
  3092. The options to defclass can be extended. An implementation must signal an error
  3093. if it observes a class option or a slot option that is not implemented locally.
  3094.  
  3095. It is valid to specify more than one reader, writer, accessor, or
  3096. initialization argument for a slot. No other slot option may appear more than
  3097. once in a single slot description, or an error is signaled.
  3098.  
  3099. If no reader, writer, or accessor is specified for a slot, the slot can be
  3100. accessed only by the function slot-value.
  3101.  
  3102. See sections 28.1.2, 28.1.3, 28.1.10, 28.1.5, 28.1.9 as well as slot-value,
  3103. make-instance, and initialize-instance.
  3104.  
  3105. [Macro]
  3106.  
  3107. defgeneric function-name lambda-list
  3108.                [[?option | {method-description}*]]
  3109.  
  3110. function-name ::= {symbol | (setf symbol)}
  3111. lambda-list ::= ({var}*
  3112.                 [&optional {var | (var)}*]
  3113.                 [&rest var]
  3114.                 [&key {keyword-parameter}* [&allow-other-keys]])
  3115. keyword-parameter ::= var | ({var | (keyword var)})
  3116. option ::= (:argument-precedence-order {parameter-name}+)
  3117.                 | (declare {declaration}+)
  3118.                 | (:documentation string)
  3119.                 | (:method-combination symbol {arg}*)
  3120.                 | (:generic-function-class class-name)
  3121.                 | (:method-class class-name)
  3122. method-description ::= (:method {method-qualifier}*
  3123.                         specialized-lambda-list
  3124.                 [[ {declaration}* | documentation ]]
  3125.                 {form}*)
  3126. method-qualifier ::= non-nil-atom
  3127. specialized-lambda-list ::=
  3128.      ({var | (var parameter-specializer-name)}*
  3129.       [&optional {var | (var [initform [supplied-p-parameter]])}*]
  3130.       [&rest var]
  3131.       [&key {specialized-keyword-parameter}* [&allow-other-keys]]
  3132.       [&aux {var | (var [initform])}*])
  3133. specialized-keyword-parameter ::=
  3134.    var | ({var | (keyword var)} [initform [supplied-p-parameter]])
  3135. parameter-specializer-name ::= symbol | (eql eql-specializer-form)
  3136.  
  3137. The macro defgeneric is used to define a generic function or to specify options
  3138. and declarations that pertain to a generic function as a whole.
  3139.  
  3140. If (fboundp function-name) is nil, a new generic function is created. If
  3141. (fdefinition function-specifier) is a generic function, that generic function
  3142. is modified. If function-name/ names a non-generic function, a macro, or a
  3143. special form, an error is signaled.
  3144.  
  3145. [X3J13 voted in March 1989 (FUNCTION-NAME)   to use fdefinition in the previous
  3146. paragraph, as shown, rather than symbol-function, as it appeared in the
  3147. original report on CLOS [5,7]. The vote also changed all occurrences of
  3148. function-specifier in the original report to function-name; this change is
  3149. reflected here.-GLS]
  3150.  
  3151. Each method-description defines a method on the generic function. The
  3152. lambda-list of each method must be congruent with the lambda-list specified by
  3153. the lambda-list option. If this condition does not hold, an error is signaled.
  3154. See section 28.1.6.4 for a definition of congruence in this context.
  3155.  
  3156. The macro defgeneric returns the generic function object as its result.
  3157.  
  3158. The function-name argument is a non-nil symbol or a list of the form (setf
  3159. symbol).
  3160.  
  3161. The lambda-list argument is an ordinary function lambda-list with the following
  3162. exceptions:
  3163.  
  3164.    *  The use of &aux is not allowed.
  3165.  
  3166.    *  Optional and keyword arguments may not have default initial value forms
  3167.      nor use supplied-p parameters. The generic function passes to the method
  3168.      all the argument values passed to it, and only those; default values are
  3169.      not supported. Note that optional and keyword arguments in method
  3170.      definitions, however, can have default initial value forms and can use
  3171.      supplied-p parameters.
  3172.  
  3173. The following options are provided. A given option may occur only once, or an
  3174. error is signaled.
  3175.  
  3176.    *  The :argument-precedence-order option is used to specify the order in
  3177.      which the required arguments in a call to the generic function are tested
  3178.      for specificity when selecting a particular method. Each required
  3179.      argument, as specified in the lambda-list argument, must be included
  3180.      exactly once as a parameter-name so that the full and unambiguous
  3181.      precedence order is supplied. If this condition is not met, an error is
  3182.      signaled.
  3183.  
  3184.    *  The declare option is used to specify declarations that pertain to the
  3185.      generic function. The following standard Common Lisp declaration is
  3186.      allowed:
  3187.  
  3188.         o  An optimize declaration specifies whether method selection should be
  3189.           optimized for speed or space, but it has no effect on methods. To
  3190.           control how a method is optimized, an optimize declaration must be
  3191.           placed directly in the defmethod form or method description. The
  3192.           optimization qualities speed and space are the only qualities this
  3193.           standard requires, but an implementation can extend the Common Lisp
  3194.           Object System to recognize other qualities. A simple implementation
  3195.           that has only one method selection technique and ignores the optimize
  3196.           declaration is valid.
  3197.  
  3198.      The special, ftype, function, inline, notinline, and declaration
  3199.      declarations are not permitted. Individual implementations can extend the
  3200.      declare option to support additional declarations. If an implementation
  3201.      notices a declaration that it does not support and that has not been
  3202.      proclaimed as a non-standard declaration name in a declaration
  3203.      proclamation, it should issue a warning.
  3204.  
  3205.    *  The :documentation argument associates a documentation string with the
  3206.      generic function. The documentation type for this string is function. The
  3207.      form (documentation function-name/ 'function) may be used to retrieve this
  3208.      string.
  3209.  
  3210.    *  The :generic-function-class option may be used to specify that the
  3211.      generic function is to have a different class than the default provided by
  3212.      the system (the class standard-generic-function). The class-name argument
  3213.      is the name of a class that can be the class of a generic function. If
  3214.      function-name specifies an existing generic function that has a different
  3215.      value for the :generic-function-class argument and the new generic
  3216.      function class is compatible with the old, change-class is called to
  3217.      change the class of the generic function; otherwise an error is signaled.
  3218.  
  3219.    *  The :method-class option is used to specify that all methods on this
  3220.      generic function are to have a different class from the default provided
  3221.      by the system (the class standard-method). The class-name argument is the
  3222.      name of a class that is capable of being the class of a method.
  3223.  
  3224.    *  The :method-combination option is followed by a symbol that names a type
  3225.      of method combination. The arguments (if any) that follow that symbol
  3226.      depend on the type of method combination. Note that the standard method
  3227.      combination type does not support any arguments. However, all types of
  3228.      method combination defined by the short form of define-method-combination
  3229.      accept an optional argument named order, defaulting to
  3230.      :most-specific-first, where a value of :most-specific-last reverses the
  3231.      order of the primary methods without affecting the order of the auxiliary
  3232.      methods.
  3233.  
  3234. The method-description arguments define methods that will be associated with
  3235. the generic function. The method-qualifier and specialized-lambda-list
  3236. arguments in a method description are the same as for defmethod.
  3237.  
  3238. The form arguments specify the method body. The body of the method is enclosed
  3239. in an implicit block. If function-name is a symbol, this block bears the same
  3240. name as the generic function. If function-name is a list of the form (setf
  3241. symbol), the name of the block is symbol.
  3242.  
  3243. The generic function object is returned as the result.
  3244.  
  3245. The effect of the defgeneric macro is as if the following three steps were
  3246. performed: first, methods defined by previous defgeneric forms are removed;
  3247. second, ensure-generic-function is called; and finally, methods specified by
  3248. the current defgeneric form are added to the generic function.
  3249.  
  3250. If no method descriptions are specified and a generic function of the same name
  3251. does not already exist, a generic function with no methods is created.
  3252.  
  3253. The lambda-list argument of defgeneric specifies the shape of lambda-lists for
  3254. the methods on this generic function. All methods on the resulting generic
  3255. function must have lambda-lists that are congruent with this shape. If a
  3256. defgeneric form is evaluated and some methods for that generic function have
  3257. lambda-lists that are not congruent with that given in the defgeneric form, an
  3258. error is signaled. For further details on method congruence, see section
  3259. 28.1.6.4.
  3260.  
  3261. Implementations can extend defgeneric to include other options. It is required
  3262. that an implementation signal an error if it observes an option that is not
  3263. implemented locally.
  3264.  
  3265. See section 28.1.6.4 as well as defmethod, ensure-generic-function, and
  3266. generic-function.
  3267.  
  3268. [Macro]
  3269.  
  3270. define-method-combination name [[?short-form-option]]
  3271. define-method-combination name lambda-list
  3272.                           ({method-group-specifier}*)
  3273.                           [(:arguments . lambda-list)]
  3274.                           [(:generic-function generic-fn-symbol)]
  3275.                           [[{declaration}* | doc-string]]
  3276.                           {form}*
  3277.  
  3278. short-form-option ::= :documentation string
  3279.                 | :identity-with-one-argument boolean
  3280.                 | :operator operator
  3281. method-group-specifier ::= (variable {{qualifier-pattern}+ | predicate}
  3282.                 [[?long-form-option]])
  3283. long-form-option ::= :description format-string
  3284.                 | :order order
  3285.                 | :required boolean
  3286.  
  3287. The macro define-method-combination is used to define new types of method
  3288. combination.
  3289.  
  3290. There are two forms of define-method-combination. The short form is a simple
  3291. facility for the cases that are expected to be most commonly needed. The long
  3292. form is more powerful but more verbose. It resembles defmacro in that the body
  3293. is an expression, usually using backquote, that computes a Lisp form. Thus
  3294. arbitrary control structures can be implemented. The long form also allows
  3295. arbitrary processing of method qualifiers.
  3296.  
  3297. In both the short and long forms, name is a symbol. By convention, non-keyword,
  3298. non-nil symbols are usually used.
  3299.  
  3300. The short-form syntax of define-method-combination is recognized when the
  3301. second subform is a non-nil symbol or is not present. When the short form is
  3302. used, name is defined as a type of method combination that produces a Lisp form
  3303. (operator method-call method-call ... ). The operator is a symbol that can be
  3304. the name of a function, macro, or special form. The operator can be specified
  3305. by a keyword option; it defaults to name.
  3306.  
  3307. Keyword options for the short form are the following:
  3308.  
  3309.    *  The :documentation option is used to document the method-combination
  3310.      type.
  3311.  
  3312.    *  The :identity-with-one-argument option enables an optimization when
  3313.      boolean is true (the default is false). If there is exactly one applicable
  3314.      method and it is a primary method, that method serves as the effective
  3315.      method and operator is not called. This optimization avoids the need to
  3316.      create a new effective method and avoids the overhead of a function call.
  3317.      This option is designed to be used with operators such as progn, and, +,
  3318.      and max.
  3319.  
  3320.    *  The :operator option specifies the name of the operator. The operator
  3321.      argument is a symbol that can be the name of a function, macro, or special
  3322.      form. By convention, name and operator are often the same symbol. This is
  3323.      the default, but it is not required.
  3324.  
  3325. None of the subforms is evaluated.
  3326.  
  3327. These types of method combination require exactly one qualifier per method. An
  3328. error is signaled if there are applicable methods with no qualifiers or with
  3329. qualifiers that are not supported by the method combination type.
  3330.  
  3331. A method combination procedure defined in this way recognizes two roles for
  3332. methods. A method whose one qualifier is the symbol naming this type of method
  3333. combination is defined to be a primary method. At least one primary method must
  3334. be applicable or an error is signaled. A method with :around as its one
  3335. qualifier is an auxiliary method that behaves the same as an :around method in
  3336. standard method combination. The function call-next-method can be used only in
  3337. :around methods; it cannot be used in primary methods defined by the short form
  3338. of the define-method-combination macro.
  3339.  
  3340. A method combination procedure defined in this way accepts an optional argument
  3341. named order, which defaults to :most-specific-first. A value of
  3342. :most-specific-last reverses the order of the primary methods without affecting
  3343. the order of the auxiliary methods.
  3344.  
  3345. The short form automatically includes error checking and support for :around
  3346. methods.
  3347.  
  3348. For a discussion of built-in method combination types, see section 28.1.7.4.
  3349.  
  3350. The long-form syntax of define-method-combination is recognized when the second
  3351. subform is a list.
  3352.  
  3353. The lambda-list argument is an ordinary lambda-list. It receives any arguments
  3354. provided after the name of the method combination type in the
  3355. :method-combination option to defgeneric.
  3356.  
  3357. A list of method group specifiers follows. Each specifier selects a subset of
  3358. the applicable methods to play a particular role, either by matching their
  3359. qualifiers against some patterns or by testing their qualifiers with a
  3360. predicate. These method group specifiers define all method qualifiers that can
  3361. be used with this type of method combination. If an applicable method does not
  3362. fall into any method group, the system signals the error that the method is
  3363. invalid for the kind of method combination in use.
  3364.  
  3365. Each method group specifier names a variable. During the execution of the forms
  3366. in the body of define-method-combination, this variable is bound to a list of
  3367. the methods in the method group. The methods in this list occur in
  3368. most-specific-first order.
  3369.  
  3370. A qualifier pattern is a list or the symbol *. A method matches a qualifier
  3371. pattern if the method's list of qualifiers is equal to the qualifier pattern
  3372. (except that the symbol * in a qualifier pattern matches anything). Thus a
  3373. qualifier pattern can be one of the following: the empty list (), which matches
  3374. unqualified methods; the symbol *, which matches all methods; a true list,
  3375. which matches methods with the same number of qualifiers as the length of the
  3376. list when each qualifier matches the corresponding list element; or a dotted
  3377. list that ends in the symbol * (the * matches any number of additional
  3378. qualifiers).
  3379.  
  3380. Each applicable method is tested against the qualifier patterns and predicates
  3381. in left-to-right order. As soon as a qualifier pattern matches or a predicate
  3382. returns true, the method becomes a member of the corresponding method group and
  3383. no further tests are made. Thus if a method could be a member of more than one
  3384. method group, it joins only the first such group. If a method group has more
  3385. than one qualifier pattern, a method need only satisfy one of the qualifier
  3386. patterns to be a member of the group.
  3387.  
  3388. The name of a predicate function can appear instead of qualifier patterns in a
  3389. method group specifier. The predicate is called for each method that has not
  3390. been assigned to an earlier method group; it is called with one argument, the
  3391. method's qualifier list. The predicate should return true if the method is to
  3392. be a member of the method group. A predicate can be distinguished from a
  3393. qualifier pattern because it is a symbol other than nil or *.
  3394.  
  3395. If there is an applicable method whose qualifiers are not valid for the method
  3396. combination type, the function invalid-method-error is called.
  3397.  
  3398. Method group specifiers can have keyword options following the qualifier
  3399. patterns or predicate. Keyword options can be distinguished from additional
  3400. qualifier patterns because they are neither lists nor the symbol *. The keyword
  3401. options are:
  3402.  
  3403.    *  The :description option is used to provide a description of the role of
  3404.      methods in the method group. Programming environment tools use (apply
  3405.      #'format stream format-string (method-qualifiers method)) to print this
  3406.      description, which is expected to be concise. This keyword option allows
  3407.      the description of a method qualifier to be defined in the same module
  3408.      that defines the meaning of the method qualifier. In most cases,
  3409.      format-string will not contain any format directives, but they are
  3410.      available for generality. If :description is not specified, a default
  3411.      description is generated based on the variable name and the qualifier
  3412.      patterns and on whether this method group includes the unqualified
  3413.      methods. The argument format-string is not evaluated.
  3414.  
  3415.    *  The :order option specifies the order of methods. The order argument is a
  3416.      form that evaluates to :most-specific-first or :most-specific-last. If it
  3417.      evaluates to any other value, an error is signaled. This keyword option is
  3418.      a convenience and does not add any expressive power. If :order is not
  3419.      specified, it defaults to :most-specific-first.
  3420.  
  3421.    *  The :required option specifies whether at least one method in this method
  3422.      group is required. If the boolean argument is non-nil and the method group
  3423.      is empty (that is, no applicable methods match the qualifier patterns or
  3424.      satisfy the predicate), an error is signaled. This keyword option is a
  3425.      convenience and does not add any expressive power. If :required is not
  3426.      specified, it defaults to nil. The boolean argument is not evaluated.
  3427.  
  3428. The use of method group specifiers provides a convenient syntax to select
  3429. methods, to divide them among the possible roles, and to perform the necessary
  3430. error checking. It is possible to perform further filtering of methods in the
  3431. body forms by using normal list-processing operations and the functions
  3432. method-qualifiers and invalid-method-error. It is permissible to use setq on
  3433. the variables named in the method group specifiers and to bind additional
  3434. variables. It is also possible to bypass the method group specifier mechanism
  3435. and do everything in the body forms. This is accomplished by writing a single
  3436. method group with * as its only qualifier pattern; the variable is then bound
  3437. to a list of all of the applicable methods, in most-specific-first order.
  3438.  
  3439. The body forms compute and return the Lisp form that specifies how the methods
  3440. are combined, that is, the effective method. The effective method uses the
  3441. macro call-method. The definition of this macro has lexical scope and is
  3442. available only in an effective method form. Given a method object in one of the
  3443. lists produced by the method group specifiers and a list of next methods, the
  3444. macro call-method will invoke the method so that call-next-method will have
  3445. available the next methods.
  3446.  
  3447. When an effective method has no effect other than to call a single method, some
  3448. implementations employ an optimization that uses the single method directly as
  3449. the effective method, thus avoiding the need to create a new effective method.
  3450. This optimization is active when the effective method form consists entirely of
  3451. an invocation of the call-method macro whose first subform is a method object
  3452. and whose second subform is nil. Each define-method-combination body is
  3453. responsible for stripping off redundant invocations of progn, and,
  3454. multiple-value-prog1, and the like, if this optimization is desired.
  3455.  
  3456. The list (:arguments . lambda-list) can appear before any declaration or
  3457. documentation string. This form is useful when the method combination type
  3458. performs some specific behavior as part of the combined method and that
  3459. behavior needs access to the arguments to the generic function. Each parameter
  3460. variable defined by lambda-list is bound to a form that can be inserted into
  3461. the effective method. When this form is evaluated during execution of the
  3462. effective method, its value is the corresponding argument to the generic
  3463. function. If lambda-list is not congruent to the generic function's
  3464. lambda-list, additional ignored parameters are automatically inserted until it
  3465. is congruent. Thus it is permissible for lambda-list to receive fewer arguments
  3466. than the number that the generic function expects.
  3467.  
  3468. Erroneous conditions detected by the body should be reported with
  3469. method-combination-error or invalid-method-error; these functions add any
  3470. necessary contextual information to the error message and will signal the
  3471. appropriate error.
  3472.  
  3473. The body forms are evaluated inside the bindings created by the lambda-list and
  3474. method group specifiers. Declarations at the head of the body are positioned
  3475. directly inside bindings created by the lambda-list and outside the bindings of
  3476. the method group variables. Thus method group variables cannot be declared.
  3477.  
  3478. Within the body forms, generic-function-symbol is bound to the generic function
  3479. object.
  3480.  
  3481. If a doc-string argument is present, it provides the documentation for the
  3482. method combination type.
  3483.  
  3484. The functions method-combination-error and invalid-method-error can be called
  3485. from the body forms or from functions called by the body forms. The actions of
  3486. these two functions can depend on implementation-dependent dynamic variables
  3487. automatically bound before the generic function compute-effective-method is
  3488. called.
  3489.  
  3490. Note that two methods with identical specializers, but with different
  3491. qualifiers, are not ordered by the algorithm described in step 2 of the method
  3492. selection and combination process described in section 28.1.7. Normally the two
  3493. methods play different roles in the effective method because they have
  3494. different qualifiers, and no matter how they are ordered in the result of step
  3495. 2 the effective method is the same. If the two methods play the same role and
  3496. their order matters, an error is signaled. This happens as part of the
  3497. qualifier pattern matching in define-method-combination.
  3498.  
  3499. The value returned by the define-method-combination macro is the new method
  3500. combination object.
  3501.  
  3502. Most examples of the long form of define-method-combination also illustrate the
  3503. use of the related functions that are provided as part of the declarative
  3504. method combination facility.
  3505.  
  3506. ;;; Examples of the short form of define-method-combination
  3507.  
  3508. (define-method-combination and :identity-with-one-argument t)
  3509.  
  3510. (defmethod func and ((x class1) y)
  3511.   ...)
  3512.  
  3513. ;;; The equivalent of this example in the long form is:
  3514.  
  3515. (define-method-combination and
  3516.         (&optional (order ':most-specific-first))
  3517.         ((around (:around))
  3518.          (primary (and) :order order :required t))
  3519.   (let ((form (if (rest primary)
  3520.                   `(and ,@(mapcar #'(lambda (method)
  3521.                                       `(call-method ,method ()))
  3522.                                   primary))
  3523.                   `(call-method ,(first primary) ()))))
  3524.     (if around
  3525.         `(call-method ,(first around)
  3526.                       (,@(rest around)
  3527.                        (make-method ,form)))
  3528.         form)))
  3529.  
  3530. ;;; Examples of the long form of define-method-combination
  3531.  
  3532. ;;; The default method-combination technique
  3533.  
  3534. (define-method-combination standard ()
  3535.         ((around (:around))
  3536.          (before (:before))
  3537.          (primary () :required t)
  3538.          (after (:after)))
  3539.   (flet ((call-methods (methods)
  3540.            (mapcar #'(lambda (method)
  3541.                        `(call-method ,method ()))
  3542.                    methods)))
  3543.     (let ((form (if (or before after (rest primary))
  3544.                     `(multiple-value-prog1
  3545.                        (progn ,@(call-methods before)
  3546.                               (call-method ,(first primary)
  3547.                                            ,(rest primary)))
  3548.                        ,@(call-methods (reverse after)))
  3549.                     `(call-method ,(first primary) ()))))
  3550.       (if around
  3551.           `(call-method ,(first around)
  3552.                         (,@(rest around)
  3553.                          (make-method ,form)))
  3554.           form))))
  3555.  
  3556. ;;; A simple way to try several methods until one returns non-nil
  3557.  
  3558. (define-method-combination or ()
  3559.         ((methods (or)))
  3560.   `(or ,@(mapcar #'(lambda (method)
  3561.                      `(call-method ,method ()))
  3562.                  methods)))
  3563.  
  3564. ;;; A more complete version of the preceding
  3565.  
  3566. (define-method-combination or
  3567.         (&optional (order ':most-specific-first))
  3568.         ((around (:around))
  3569.          (primary (or)))
  3570.   ;; Process the order argument
  3571.   (case order
  3572.     (:most-specific-first)
  3573.     (:most-specific-last (setq primary (reverse primary)))
  3574.     (otherwise (method-combination-error
  3575.                  "~S is an invalid order.~@
  3576.                   :most-specific-first and :most-specific-last ~
  3577.                     are the possible values."
  3578.                                          order)))
  3579.   ;; Must have a primary method
  3580.   (unless primary
  3581.     (method-combination-error "A primary method is required."))
  3582.   ;; Construct the form that calls the primary methods
  3583.   (let ((form (if (rest primary)
  3584.                   `(or ,@(mapcar #'(lambda (method)
  3585.                                      `(call-method ,method ()))
  3586.                                  primary))
  3587.                   `(call-method ,(first primary) ()))))
  3588.     ;; Wrap the around methods around that form
  3589.     (if around
  3590.         `(call-method ,(first around)
  3591.                       (,@(rest around)
  3592.                        (make-method ,form)))
  3593.         form)))
  3594.  
  3595. ;;; The same thing, using the :order and :required keyword options
  3596. (define-method-combination or
  3597.         (&optional (order ':most-specific-first))
  3598.         ((around (:around))
  3599.          (primary (or) :order order :required t))
  3600.   (let ((form (if (rest primary)
  3601.                   `(or ,@(mapcar #'(lambda (method)
  3602.                                      `(call-method ,method ()))
  3603.                                  primary))
  3604.                   `(call-method ,(first primary) ()))))
  3605.     (if around
  3606.         `(call-method ,(first around)
  3607.                       (,@(rest around)
  3608.                        (make-method ,form)))
  3609.         form)))
  3610.  
  3611. ;;; This short-form call is behaviorally identical to the preceding.
  3612. (define-method-combination or :identity-with-one-argument t)
  3613.  
  3614. ;;; Order methods by positive integer qualifiers; note that :around
  3615. ;;; methods are disallowed here in order to keep the example small.
  3616.  
  3617. (define-method-combination example-method-combination ()
  3618.         ((methods positive-integer-qualifier-p))
  3619.   `(progn ,@(mapcar #'(lambda (method)
  3620.                         `(call-method ,method ()))
  3621.                     (stable-sort methods #'<
  3622.                       :key #'(lambda (method)
  3623.                                (first (method-qualifiers
  3624.                                         method)))))))
  3625.  
  3626. (defun positive-integer-qualifier-p (method-qualifiers)
  3627.   (and (= (length method-qualifiers) 1)
  3628.        (typep (first method-qualifiers) '(integer 0 *))))
  3629.  
  3630. ;;; Example of the use of :arguments
  3631. (define-method-combination progn-with-lock ()
  3632.         ((methods ()))
  3633.         (:arguments object)
  3634.   `(unwind-protect
  3635.        (progn (lock (object-lock ,object))
  3636.               ,@(mapcar #'(lambda (method)
  3637.                             `(call-method ,method ()))
  3638.                         methods))
  3639.      (unlock (object-lock ,object))))
  3640.  
  3641. The :method-combination option of defgeneric is used to specify that a generic
  3642. function should use a particular method combination type. The argument to the
  3643. :method-combination option is the name of a method combination type.
  3644.  
  3645. See sections 28.1.7 and 28.1.7.4 as well as call-method, method-qualifiers,
  3646. method-combination-error, invalid-method-error, and defgeneric.
  3647.  
  3648. [Macro]
  3649.  
  3650. defmethod function-name {method-qualifier}*
  3651.           specialized-lambda-list
  3652.           [[ {declaration}* | doc-string]]
  3653.           {form}*
  3654.  
  3655. function-name ::= {symbol | (setf symbol)}
  3656. method-qualifier ::= non-nil-atom
  3657. parameter-specializer-name ::= symbol | (eql eql-specializer-form)
  3658.  
  3659. The macro defmethod defines a method on a generic function.
  3660.  
  3661. If (fboundp function-name) is nil, a generic function is created with default
  3662. values for the argument precedence order (each argument is more specific than
  3663. the arguments to its right in the argument list), for the generic function
  3664. class (the class standard-generic-function), for the method class (the class
  3665. standard-method), and for the method combination type (the standard method
  3666. combination type). The lambda-list of the generic function is congruent with
  3667. the lambda-list of the method being defined; if the defmethod form mentions
  3668. keyword arguments, the lambda-list of the generic function will mention &key
  3669. (but no keyword arguments). If function-name names a non-generic function, a
  3670. macro, or a special form, an error is signaled.
  3671.  
  3672. If a generic function is currently named by function-name, where function-name
  3673. is a symbol or a list of the form (setf symbol), the lambda-list of the method
  3674. must be congruent with the lambda-list of the generic function. If this
  3675. condition does not hold, an error is signaled. See section 28.1.6.4 for a
  3676. definition of congruence in this context.
  3677.  
  3678. The function-name argument is a non-nil symbol or a list of the form (setf
  3679. symbol). It names the generic function on which the method is defined.
  3680.  
  3681. Each method-qualifier argument is an object that is used by method combination
  3682. to identify the given method. A method qualifier is a non-nil atom. The method
  3683. combination type may further restrict what a method qualifier may be. The
  3684. standard method combination type allows for unqualified methods or methods
  3685. whose sole qualifier is the keyword :before, the keyword :after, or the keyword
  3686. :around.
  3687.  
  3688. A specialized-lambda-list is like an ordinary function lambda-list except that
  3689. the name of a required parameter can be replaced by a specialized parameter, a
  3690. list of the form (variable-name parameter-specializer-name). Only required
  3691. parameters may be specialized. A parameter specializer name is a symbol that
  3692. names a class or (eql eql-specializer-form). The parameter specializer name
  3693. (eql eql-specializer-form) indicates that the corresponding argument must be
  3694. eql to the object that is the value of eql-specializer-form for the method to
  3695. be applicable. If no parameter specializer name is specified for a given
  3696. required parameter, the parameter specializer defaults to the class named t.
  3697. See section 28.1.6.2.
  3698.  
  3699. The form arguments specify the method body. The body of the method is enclosed
  3700. in an implicit block. If function-name is a symbol, this block bears the same
  3701. name as the generic function. If function-name is a list of the form (setf
  3702. symbol), the name of the block is symbol.
  3703.  
  3704. The result of defmethod is the method object.
  3705.  
  3706. The class of the method object that is created is that given by the method
  3707. class option of the generic function on which the method is defined.
  3708.  
  3709. If the generic function already has a method that agrees with the method being
  3710. defined on parameter specializers and qualifiers, defmethod replaces the
  3711. existing method with the one now being defined. See section 28.1.6.3 for a
  3712. definition of agreement in this context.
  3713.  
  3714. The parameter specializers are derived from the parameter specializer names as
  3715. described in section 28.1.6.2.
  3716.  
  3717. The expansion of the defmethod macro refers to each specialized parameter (see
  3718. the ignore declaration specifier), including parameters that have an explicit
  3719. parameter specializer name of t. This means that a compiler warning does not
  3720. occur if the body of the method does not refer to a specialized parameter. Note
  3721. that a parameter that specializes on t is not synonymous with an unspecialized
  3722. parameter in this context.
  3723.  
  3724. See sections 28.1.6.2, 28.1.6.4, and 28.1.6.3.
  3725.  
  3726. [At this point the original CLOS report [5,7] contained a specification for
  3727. describe as a generic function. This specification is omitted here because
  3728. X3J13 voted in March 1989 (DESCRIBE-UNDERSPECIFIED)   not to make describe a
  3729. generic function after all (see describe-object).-GLS]
  3730.  
  3731. [Generic function]
  3732. documentation x &optional doc-type
  3733.  
  3734. [Primary method]
  3735.  
  3736. documentation (method standard-method) &optional doc-type
  3737. documentation (generic-function standard-generic-function)
  3738.        &optional doc-type
  3739. documentation (class standard-class) &optional doc-type
  3740. documentation (method-combination method-combination)
  3741.        &optional doc-type
  3742. documentation (slot-description standard-slot-description)
  3743.        &optional doc-type
  3744. documentation (symbol symbol) &optional doc-type
  3745. documentation (list list) &optional doc-type
  3746.  
  3747. The ordinary function documentation (see section 25.2) is replaced by a generic
  3748. function. The generic function documentation returns the documentation string
  3749. associated with the given object if it is available; otherwise documentation
  3750. returns nil.
  3751.  
  3752. The first argument of documentation is a symbol, a function-name list of the
  3753. form (setf symbol), a method object, a class object, a generic function object,
  3754. a method combination object, or a slot description object. Whether a second
  3755. argument should be supplied depends on the type of the first argument.
  3756.  
  3757.    *  If the first argument is a method object, a class object, a generic
  3758.      function object, a method combination object, or a slot description
  3759.      object, the second argument must not be supplied, or an error is signaled.
  3760.  
  3761.    *  If the first argument is a symbol or a list of the form (setf symbol),
  3762.      the second argument must be supplied.
  3763.  
  3764.         o  The forms
  3765.  
  3766.           (documentation symbol 'function)
  3767.  
  3768.           and
  3769.  
  3770.           (documentation '(setf symbol) 'function)
  3771.  
  3772.           return the documentation string of the function, generic function,
  3773.           special form, or macro named by the symbol or list.
  3774.  
  3775.         o  The form (documentation symbol 'variable) returns the documentation
  3776.           string of the special variable or constant named by the symbol.
  3777.  
  3778.         o  The form (documentation symbol 'structure) returns the documentation
  3779.           string of the defstruct structure named by the symbol.
  3780.  
  3781.         o  The form (documentation symbol 'type) returns the documentation
  3782.           string of the class object named by the symbol, if there is such a
  3783.           class. If there is no such class, it returns the documentation string
  3784.           of the type specifier named by the symbol.
  3785.  
  3786.         o  The form (documentation symbol 'setf) returns the documentation
  3787.           string of the defsetf or define-setf-method definition associated
  3788.           with the symbol.
  3789.  
  3790.         o  The form (documentation symbol 'method-combination) returns the
  3791.           documentation string of the method combination type named by the
  3792.           symbol.
  3793.  
  3794. An implementation may extend the set of symbols that are acceptable as the
  3795. second argument. If a symbol is not recognized as an acceptable argument by the
  3796. implementation, an error must be signaled.
  3797.  
  3798. The documentation string associated with the given object is returned unless
  3799. none is available, in which case documentation returns nil.
  3800.  
  3801. [Generic function]
  3802. (setf documentation) new-value x &optional doc-type
  3803.  
  3804. [Primary method]
  3805.  
  3806. (setf documentation) new-value
  3807.       (method standard-method) &optional doc-type
  3808. (setf documentation) new-value
  3809.       (generic-function standard-generic-function) &optional doc-type
  3810. (setf documentation) new-value
  3811.       (class standard-class) &optional doc-type
  3812. (setf documentation) new-value
  3813.       (method-combination method-combination) &optional doc-type
  3814. (setf documentation) new-value
  3815.       (slot-description standard-slot-description) &optional doc-type
  3816. (setf documentation) new-value
  3817.       (symbol symbol) &optional doc-type
  3818. (setf documentation) new-value
  3819.       (list list) &optional doc-type
  3820.  
  3821. The generic function (setf documentation) is used to update the documentation.
  3822.  
  3823. The first argument of (setf documentation) is the new documentation.
  3824.  
  3825. The second argument of documentation is a symbol, a function-name list of the
  3826. form (setf symbol), a method object, a class object, a generic function object,
  3827. a method combination object, or a slot description object. Whether a third
  3828. argument should be supplied depends on the type of the second argument. See
  3829. documentation.
  3830.  
  3831. [Function]
  3832. ensure-generic-function function-name &key
  3833. :lambda-list:argument-precedence-order:declare:documentation:generic-function-class:method-combination:method-class:environment
  3834.  
  3835. function-name ::= {symbol | (setf symbol)}
  3836.  
  3837. The function ensure-generic-function is used to define a globally named generic
  3838. function with no methods or to specify or modify options and declarations that
  3839. pertain to a globally named generic function as a whole.
  3840.  
  3841. If (fboundp function-name) is nil, a new generic function is created. If
  3842. (fdefinition function-name) is a non-generic function, a macro, or a special
  3843. form, an error is signaled.
  3844.  
  3845. [X3J13 voted in March 1989 (FUNCTION-NAME)   to use fdefinition in the previous
  3846. paragraph, as shown, rather than symbol-function, as it appeared in the
  3847. original report on CLOS [5,7]. The vote also changed all occurrences of
  3848. function-specifier in the original report to function-name; this change is
  3849. reflected here.-GLS]
  3850.  
  3851. If function-name specifies a generic function that has a different value for
  3852. any of the following arguments, the generic function is modified to have the
  3853. new value: :argument-precedence-order, :declare, :documentation,
  3854. :method-combination.
  3855.  
  3856. If function-name specifies a generic function that has a different value for
  3857. the :lambda-list argument, and the new value is congruent with the lambda-lists
  3858. of all existing methods or there are no methods, the value is changed;
  3859. otherwise an error is signaled.
  3860.  
  3861. If function-name specifies a generic function that has a different value for
  3862. the :generic-function-class argument and if the new generic function class is
  3863. compatible with the old, change-class is called to change the class of the
  3864. generic function; otherwise an error is signaled.
  3865.  
  3866. If function-name specifies a generic function that has a different
  3867. :method-class value, the value is changed but any existing methods are not
  3868. changed.
  3869.  
  3870. The function-name argument is a symbol or a list of the form (setf symbol).
  3871.  
  3872. The keyword arguments correspond to the option arguments of defgeneric, except
  3873. that the :method-class and :generic-function-class arguments can be class
  3874. objects as well as names.
  3875.  
  3876. The :environment argument is the same as the &environment argument to macro
  3877. expansion functions. It is typically used to distinguish between compile-time
  3878. and run-time environments.
  3879.  
  3880. The :method-combination argument is a method combination object.
  3881.  
  3882. The generic function object is returned. See defgeneric.
  3883.  
  3884. [Function]
  3885. find-class symbol &optional errorp environment
  3886.  
  3887. The function find-class returns the class object named by the given symbol in
  3888. the given environment.
  3889.  
  3890. The first argument to find-class is a symbol.
  3891.  
  3892. If there is no such class and the errorp argument is not supplied or is
  3893. non-nil, find-class signals an error. If there is no such class and the errorp
  3894. argument is nil, find-class returns nil. The default value of errorp is t.
  3895.  
  3896. The optional environment argument is the same as the &environment argument to
  3897. macro expansion functions. It is typically used to distinguish between
  3898. compile-time and run-time environments.
  3899.  
  3900. The result of find-class is the class object named by the given symbol.
  3901.  
  3902. The class associated with a particular symbol can be changed by using setf with
  3903. find-class. The results are undefined if the user attempts to change the class
  3904. associated with a symbol that is defined as a type specifier in chapter 4. See
  3905. section 28.1.4.
  3906.  
  3907. [Generic function]
  3908. find-method generic-function method-qualifiers specializers &optional errorp
  3909.  
  3910. [Primary method]
  3911.  
  3912. find-method (generic-function standard-generic-function)
  3913.             method-qualifiers specializers &optional errorp
  3914.  
  3915. The generic function find-method takes a generic function and returns the
  3916. method object that agrees on method qualifiers and parameter specializers with
  3917. the method-qualifiers and specializers arguments of find-method. See section
  3918. 28.1.6.3 for a definition of agreement in this context.
  3919.  
  3920. The generic-function argument is a generic function.
  3921.  
  3922. The method-qualifiers argument is a list of the method qualifiers for the
  3923. method. The order of the method qualifiers is significant.
  3924.  
  3925. The specializers argument is a list of the parameter specializers for the
  3926. method. It must correspond in length to the number of required arguments of the
  3927. generic function, or an error is signaled. This means that to obtain the
  3928. default method on a given generic function, a list whose elements are the class
  3929. named t must be given.
  3930.  
  3931. If there is no such method and the errorp argument is not supplied or is
  3932. non-nil, find-method signals an error. If there is no such method and the
  3933. errorp argument is nil, find-method returns nil. The default value of errorp is
  3934. t.
  3935.  
  3936. The result of find-method is the method object with the given method qualifiers
  3937. and parameter specializers.
  3938.  
  3939. See section 28.1.6.3.
  3940.  
  3941. [Generic function]
  3942. function-keywords method
  3943.  
  3944. [Primary method]
  3945. function-keywords (method standard-method)
  3946.  
  3947. The generic function function-keywords is used to return the keyword parameter
  3948. specifiers for a given method.
  3949.  
  3950. The method argument is a method object.
  3951.  
  3952. The generic function function-keywords returns two values: a list of the
  3953. explicitly named keywords and a boolean that states whether &allow-other-keys
  3954. had been specified in the method definition.
  3955.  
  3956. [Special Form]
  3957.  
  3958. generic-flet ({(function-name lambda-list
  3959.                 [[?option | {method-description}* ]])}*)
  3960.              {form}*
  3961.  
  3962. The generic-flet special form is analogous to the flet special form. It
  3963. produces new generic functions and establishes new lexical function definition
  3964. bindings. Each generic function is created with the set of methods specified by
  3965. its method descriptions.
  3966.  
  3967. The special form generic-flet is used to define generic functions whose names
  3968. are meaningful only locally and to execute a series of forms with these
  3969. function definition bindings. Any number of such local generic functions may be
  3970. defined.
  3971.  
  3972. The names of functions defined by generic-flet have lexical scope; they retain
  3973. their local definitions only within the body of the generic-flet. Any
  3974. references within the body of the generic-flet to functions whose names are the
  3975. same as those defined within the generic-flet are thus references to the local
  3976. functions instead of to any global functions of the same names. The scope of
  3977. these generic function definition bindings, however, includes only the body of
  3978. generic-flet, not the definitions themselves. Within the method bodies, local
  3979. function names that match those being defined refer to global functions defined
  3980. outside the generic-flet. It is thus not possible to define recursive functions
  3981. with generic-flet.
  3982.  
  3983. The function-name, lambda-list, option, method-qualifier, and
  3984. specialized-lambda-list arguments are the same as for defgeneric.
  3985.  
  3986. A generic-flet local method definition is identical in form to the method
  3987. definition part of a defmethod.
  3988.  
  3989. The body of each method is enclosed in an implicit block. If function-name is a
  3990. symbol, this block bears the same name as the generic function. If
  3991. function-name is a list of the form (setf symbol), the name of the block is
  3992. symbol.
  3993.  
  3994. The result returned by generic-flet is the value or values returned by the last
  3995. form executed. If no forms are specified, generic-flet returns nil.
  3996.  
  3997. See generic-labels, defmethod, defgeneric, and generic-function.
  3998.  
  3999. [Macro]
  4000.  
  4001. generic-function lambda-list [[?option | {method-description}*]]
  4002.  
  4003. option ::= (:argument-precedence-order {parameter-name}+)
  4004.                 | (declare {declaration}+)
  4005.                 | (:documentation string)
  4006.                 | (:method-combination symbol {arg}*)
  4007.                 | (:generic-function-class class-name)
  4008.                 | (:method-class class-name)
  4009. method-description ::= (:method {method-qualifier}*
  4010.                                 specialized-lambda-list
  4011.                                 {declaration | documentation}*
  4012.                                 {form}*)
  4013.  
  4014. The generic-function macro creates an anonymous generic function. The generic
  4015. function is created with the set of methods specified by its method
  4016. descriptions.
  4017.  
  4018. The option, method-qualifier, and specialized-lambda-list arguments are the
  4019. same as for defgeneric.
  4020.  
  4021. The generic function object is returned as the result.
  4022.  
  4023. If no method descriptions are specified, an anonymous generic function with no
  4024. methods is created.
  4025.  
  4026. See defgeneric, generic-flet, generic-labels, and defmethod.
  4027.  
  4028. [Special Form]
  4029.  
  4030. generic-labels ((function-name lambda-list
  4031.                  [[?option | {method-description}*]])}*)
  4032.                {form}*
  4033.  
  4034. The generic-labels special form is analogous to the labels special form. It
  4035. produces new generic functions and establishes new lexical function definition
  4036. bindings. Each generic function is created with the set of methods specified by
  4037. its method descriptions.
  4038.  
  4039. The special form generic-labels is used to define generic functions whose names
  4040. are meaningful only locally and to execute a series of forms with these
  4041. function definition bindings. Any number of such local generic functions may be
  4042. defined.
  4043.  
  4044. The names of functions defined by generic-labels have lexical scope; they
  4045. retain their local definitions only within the body of the generic-labels
  4046. construct. Any references within the body of the generic-labels construct to
  4047. functions whose names are the same as those defined within the generic-labels
  4048. form are thus references to the local functions instead of to any global
  4049. functions of the same names. The scope of these generic function definition
  4050. bindings includes the method bodies themselves as well as the body of the
  4051. generic-labels construct.
  4052.  
  4053. The function-name, lambda-list, option, method-qualifier, and
  4054. specialized-lambda-list arguments are the same as for defgeneric.
  4055.  
  4056. A generic-labels local method definition is identical in form to the method
  4057. definition part of a defmethod.
  4058.  
  4059. The body of each method is enclosed in an implicit block. If function-name is a
  4060. symbol, this block bears the same name as the generic function. If
  4061. function-name is a list of the form (setf symbol), the name of the block is
  4062. symbol.
  4063.  
  4064. The result returned by generic-labels is the value or values returned by the
  4065. last form executed. If no forms are specified, generic-labels returns nil.
  4066.  
  4067. See generic-flet, defmethod, defgeneric, generic-function.
  4068.  
  4069. [Generic function]
  4070. initialize-instance instance &rest initargs
  4071.  
  4072. [Primary method]
  4073. initialize-instance (instance standard-object) &rest initargs
  4074.  
  4075. The generic function initialize-instance is called by make-instance to
  4076. initialize a newly created instance. The generic function initialize-instance
  4077. is called with the new instance and the defaulted initialization arguments.
  4078.  
  4079. The system-supplied primary method on initialize-instance initializes the slots
  4080. of the instance with values according to the initialization arguments and the
  4081. :initform forms of the slots. It does this by calling the generic function
  4082. shared-initialize with the following arguments: the instance, t (this indicates
  4083. that all slots for which no initialization arguments are provided should be
  4084. initialized according to their :initform forms) and the defaulted
  4085. initialization arguments.
  4086.  
  4087. The instance argument is the object to be initialized.
  4088.  
  4089. The initargs argument consists of alternating initialization argument names and
  4090. values.
  4091.  
  4092. The modified instance is returned as the result.
  4093.  
  4094. Programmers can define methods for initialize-instance to specify actions to be
  4095. taken when an instance is initialized. If only :after methods are defined, they
  4096. will be run after the system-supplied primary method for initialization and
  4097. therefore will not interfere with the default behavior of initialize-instance.
  4098.  
  4099. See sections 28.1.9, 28.1.9.4, and 28.1.9.2 as well as shared-initialize,
  4100. make-instance, slot-boundp, and slot-makunbound.
  4101.  
  4102. [Function]
  4103. invalid-method-error method format-string &rest args
  4104.  
  4105. The function invalid-method-error is used to signal an error when there is an
  4106. applicable method whose qualifiers are not valid for the method combination
  4107. type. The error message is constructed by using a format string and any
  4108. arguments to it. Because an implementation may need to add additional
  4109. contextual information to the error message, invalid-method-error should be
  4110. called only within the dynamic extent of a method combination function.
  4111.  
  4112. The function invalid-method-error is called automatically when a method fails
  4113. to satisfy every qualifier pattern and predicate in a define-method-combination
  4114. form. A method combination function that imposes additional restrictions should
  4115. call invalid-method-error explicitly if it encounters a method it cannot
  4116. accept.
  4117.  
  4118. The method argument is the invalid method object.
  4119.  
  4120. The format-string argument is a control string that can be given to format, and
  4121. args are any arguments required by that string.
  4122.  
  4123. Whether invalid-method-error returns to its caller or exits via throw is
  4124. implementation-dependent.
  4125.  
  4126. See define-method-combination.
  4127.  
  4128. [Generic function]
  4129. make-instance class &rest initargs
  4130.  
  4131. [Primary method]
  4132. make-instance (class standard-class) &rest initargs
  4133. make-instance (class symbol) &rest initargs
  4134.  
  4135. The generic function make-instance creates a new instance of the given class.
  4136.  
  4137. The generic function make-instance may be used as described in section 28.1.9.
  4138.  
  4139. The class argument is a class object or a symbol that names a class. The
  4140. remaining arguments form a list of alternating initialization argument names
  4141. and values.
  4142.  
  4143. If the second of the preceding methods is selected, that method invokes
  4144. make-instance on the arguments (find-class class) and initargs.
  4145.  
  4146. The initialization arguments are checked within make-instance (see section
  4147. 28.1.9).
  4148.  
  4149. The new instance is returned.
  4150.  
  4151. The meta-object protocol can be used to define new methods on make-instance to
  4152. replace the object-creation protocol.
  4153.  
  4154. See section 28.1.9 as well as defclass, initialize-instance, and class-of.
  4155.  
  4156. [Generic function]
  4157. make-instances-obsolete class
  4158.  
  4159. [Primary method]
  4160. make-instances-obsolete (class standard-class)
  4161. make-instances-obsolete (class symbol)
  4162.  
  4163. The generic function make-instances-obsolete is invoked automatically by the
  4164. system when defclass has been used to redefine an existing standard class and
  4165. the set of local slots accessible in an instance is changed or the order of
  4166. slots in storage is changed. It can also be explicitly invoked by the user.
  4167.  
  4168. The function make-instances-obsolete has the effect of initiating the process
  4169. of updating the instances of the class. During updating, the generic function
  4170. update-instance-for-redefined-class will be invoked.
  4171.  
  4172. The class argument is a class object symbol that names the class whose
  4173. instances are to be made obsolete.
  4174.  
  4175. If the second of the preceding methods is selected, that method invokes
  4176. make-instances-obsolete on (find-class class).
  4177.  
  4178. The modified class is returned. The result of make-instances-obsolete is eq to
  4179. the class argument supplied to the first of the preceding methods.
  4180.  
  4181. See section 28.1.10 as well as update-instance-for-redefined-class.
  4182.  
  4183. [Function]
  4184. method-combination-error format-string &rest args
  4185.  
  4186. The function method-combination-error is used to signal an error in method
  4187. combination. The error message is constructed by using a format string and any
  4188. arguments to it. Because an implementation may need to add additional
  4189. contextual information to the error message, method-combination-error should be
  4190. called only within the dynamic extent of a method combination function.
  4191.  
  4192. The format-string argument is a control string that can be given to format, and
  4193. args are any arguments required by that string.
  4194.  
  4195. Whether method-combination-error returns to its caller or exits via throw is
  4196. implementation-dependent.
  4197.  
  4198. See define-method-combination.
  4199.  
  4200. [Generic function]
  4201. method-qualifiers method
  4202.  
  4203. [Primary method]
  4204. method-qualifiers (method standard-method)
  4205.  
  4206. The generic function method-qualifiers returns a list of the qualifiers of the
  4207. given method.
  4208.  
  4209. The method argument is a method object.
  4210.  
  4211. A list of the qualifiers of the given method is returned.
  4212.  
  4213. Example:
  4214.  
  4215. (setq methods (remove-duplicates methods
  4216.                                  :from-end t
  4217.                                  :key #'method-qualifiers
  4218.                                  :test #'equal))
  4219.  
  4220. See define-method-combination.
  4221.  
  4222. [Function]
  4223. next-method-p
  4224.  
  4225. The locally defined function next-method-p can be used within the body of a
  4226. method defined by a method-defining form to determine whether a next method
  4227. exists.
  4228.  
  4229. The function next-method-p takes no arguments.
  4230.  
  4231. The function next-method-p returns true or false.
  4232.  
  4233. Like call-next-method, the function next-method-p has lexical scope (for it is
  4234. defined only within the body of a method defined by a method-defining form) and
  4235. indefinite extent.
  4236.  
  4237. See call-next-method.
  4238.  
  4239. [Generic function]
  4240. no-applicable-method generic-function &rest function-arguments
  4241.  
  4242. [Primary method]
  4243. no-applicable-method (generic-function t) &rest function-arguments
  4244.  
  4245. The generic function no-applicable-method is called when a generic function of
  4246. the class standard-generic-function is invoked and no method on that generic
  4247. function is applicable. The default method signals an error.
  4248.  
  4249. The generic function no-applicable-method is not intended to be called by
  4250. programmers. Programmers may write methods for it.
  4251.  
  4252. The generic-function argument of no-applicable-method is the generic function
  4253. object on which no applicable method was found.
  4254.  
  4255. The function-arguments argument is a list of the arguments to that generic
  4256. function.
  4257.  
  4258. [Generic function]
  4259. no-next-method generic-function method &rest args
  4260.  
  4261. [Primary method]
  4262.  
  4263. no-next-method (generic-function standard-generic-function)
  4264.                (method standard-method) &rest args
  4265.  
  4266. The generic function no-next-method is called by call-next-method when there is
  4267. no next method. The system-supplied method on no-next-method signals an error.
  4268.  
  4269. The generic function no-next-method is not intended to be called by
  4270. programmers. Programmers may write methods for it.
  4271.  
  4272. The generic-function argument is the generic function object to which the
  4273. method that is the second argument belongs.
  4274.  
  4275. The method argument is the method that contains the call to call-next-method
  4276. for which there is no next method.
  4277.  
  4278. The args argument is a list of the arguments to call-next-method.
  4279.  
  4280. See call-next-method.
  4281.  
  4282. [Generic function]
  4283. print-object object stream
  4284.  
  4285. [Primary method]
  4286. print-object (object standard-object) stream
  4287.  
  4288. The generic function print-object writes the printed representation of an
  4289. object to a stream. The function print-object is called by the print system; it
  4290. should not be called by the user.
  4291.  
  4292. Each implementation must provide a method on the class standard-object and
  4293. methods on enough other classes so as to ensure that there is always an
  4294. applicable method. Implementations are free to add methods for other classes.
  4295. Users can write methods for print-object for their own classes if they do not
  4296. wish to inherit an implementation-supplied method.
  4297.  
  4298. The first argument is any Lisp object. The second argument is a stream; it
  4299. cannot be t or nil.
  4300.  
  4301. The function print-object returns its first argument, the object.
  4302.  
  4303. Methods on print-object must obey the print control special variables named
  4304. *print-xxx* for various xxx. The specific details are the following:
  4305.  
  4306.    *  Each method must implement *print-escape*.
  4307.  
  4308.    *  The *print-pretty* control variable can be ignored by most methods other
  4309.      than the one for lists.
  4310.  
  4311.    *  The *print-circle* control variable is handled by the printer and can be
  4312.      ignored by methods.
  4313.  
  4314.    *  The printer takes care of *print-level* automatically, provided that each
  4315.      method handles exactly one level of structure and calls write (or an
  4316.      equivalent function) recursively if there are more structural levels. The
  4317.      printer's decision of whether an object has components (and therefore
  4318.      should not be printed when the printing depth is not less than
  4319.      *print-level*) is implementation-dependent. In some implementations its
  4320.      print-object method is not called; in others the method is called, and the
  4321.      determination that the object has components is based on what it tries to
  4322.      write to the stream.
  4323.  
  4324.    *  Methods that produce output of indefinite length must obey
  4325.      *print-length*, but most methods other than the one for lists can ignore
  4326.      it.
  4327.  
  4328.    *  The *print-base*, *print-radix*, *print-case*, *print-gensym*, and
  4329.      *print-array* control variables apply to specific types of objects and are
  4330.      handled by the methods for those objects.
  4331.  
  4332.    *  X3J13 voted in June 1989 (DATA-IO)   to add the following point. All
  4333.      methods for print-object must obey *print-readably*, which takes
  4334.      precedence over all other printer control variables. This includes both
  4335.      user-defined methods and implementation-defined methods.
  4336.  
  4337. If these rules are not obeyed, the results are undefined.
  4338.  
  4339. In general, the printer and the print-object methods should not rebind the
  4340. print control variables as they operate recursively through the structure, but
  4341. this is implementation-dependent.
  4342.  
  4343. In some implementations the stream argument passed to a print-object method is
  4344. not the original stream but is an intermediate stream that implements part of
  4345. the printer. Methods should therefore not depend on the identity of this
  4346. stream.
  4347.  
  4348. All of the existing printing functions (write, prin1, print, princ, pprint,
  4349. write-to-string, prin1-to-string, princ-to-string, the ~S and ~A format
  4350. operations, and the ~B, ~D, ~E, ~F, ~G, ~$, ~O, ~R, and ~X format operations
  4351. when they encounter a non-numeric value) are required to be changed to go
  4352. through the print-object generic function. Each implementation is required to
  4353. replace its former implementation of printing with one or more print-object
  4354. methods. Exactly which classes have methods for print-object is not specified;
  4355. it would be valid for an implementation to have one default method that is
  4356. inherited by all system-defined classes.
  4357.  
  4358. [Generic function]
  4359. reinitialize-instance instance &rest initargs
  4360.  
  4361. [Primary method]
  4362. reinitialize-instance (instance standard-object) &rest initargs
  4363.  
  4364. The generic function reinitialize-instance can be used to change the values of
  4365. local slots according to initialization arguments. This generic function is
  4366. called by the Meta-Object Protocol. It can also be called by users.
  4367.  
  4368. The system-supplied primary method for reinitialize-instance checks the
  4369. validity of initialization arguments and signals an error if an initialization
  4370. argument is supplied that is not declared valid. The method then calls the
  4371. generic function shared-initialize with the following arguments: the instance,
  4372. nil (which means no slots should be initialized according to their :initform
  4373. forms) and the initialization arguments it received.
  4374.  
  4375. The instance argument is the object to be initialized.
  4376.  
  4377. The initargs argument consists of alternating initialization argument names and
  4378. values.
  4379.  
  4380. The modified instance is returned as the result.
  4381.  
  4382. Initialization arguments are declared valid by using the :initarg option to
  4383. defclass, or by defining methods for reinitialize-instance or
  4384. shared-initialize. The keyword name of each keyword parameter specifier in the
  4385. lambda-list of any method defined on reinitialize-instance or shared-initialize
  4386. is declared a valid initialization argument name for all classes for which that
  4387. method is applicable.
  4388.  
  4389. See sections 28.1.12, 28.1.9.4, 28.1.9.2 as well as initialize-instance,
  4390. slot-boundp, update-instance-for-redefined-class,
  4391. update-instance-for-different-class, slot-makunbound, and shared-initialize.
  4392.  
  4393. [Generic function]
  4394. remove-method generic-function method
  4395.  
  4396. [Primary method]
  4397. remove-method (generic-function standard-generic-function) method
  4398.  
  4399. The generic function remove-method removes a method from a generic function. It
  4400. destructively modifies the specified generic function and returns the modified
  4401. generic function as its result.
  4402.  
  4403. The generic-function argument is a generic function object.
  4404.  
  4405. The method argument is a method object. The function remove-method does not
  4406. signal an error if the method is not one of the methods on the generic
  4407. function.
  4408.  
  4409. The modified generic function is returned. The result of remove-method is eq to
  4410. the generic-function argument.
  4411.  
  4412. See find-method.
  4413.  
  4414. [Generic function]
  4415. shared-initialize instance slot-names &rest initargs
  4416.  
  4417. [Primary method]
  4418.  
  4419. shared-initialize (instance standard-object)
  4420.          slot-names &rest initargs
  4421.  
  4422. The generic function shared-initialize is used to fill the slots of an instance
  4423. using initialization arguments and :initform forms. It is called when an
  4424. instance is created, when an instance is re-initialized, when an instance is
  4425. updated to conform to a redefined class, and when an instance is updated to
  4426. conform to a different class. The generic function shared-initialize is called
  4427. by the system-supplied primary method for initialize-instance,
  4428. reinitialize-instance, update-instance-for-redefined-class, and
  4429. update-instance-for-different-class.
  4430.  
  4431. The generic function shared-initialize takes the following arguments: the
  4432. instance to be initialized, a specification of a set of names of slots
  4433. accessible in that instance, and any number of initialization arguments. The
  4434. arguments after the first two must form an initialization argument list. The
  4435. system-supplied primary method on shared-initialize initializes the slots with
  4436. values according to the initialization arguments and specified :initform forms.
  4437. The second argument indicates which slots should be initialized according to
  4438. their :initform forms if no initialization arguments are provided for those
  4439. slots.
  4440.  
  4441. The system-supplied primary method behaves as follows, regardless of whether
  4442. the slots are local or shared:
  4443.  
  4444.    *  If an initialization argument in the initialization argument list
  4445.      specifies a value for that slot, that value is stored into the slot, even
  4446.      if a value has already been stored in the slot before the method is run.
  4447.  
  4448.    *  Any slots indicated by the second argument that are still unbound at this
  4449.      point are initialized according to their :initform forms. For any such
  4450.      slot that has an :initform form, that form is evaluated in the lexical
  4451.      environment of its defining defclass form and the result is stored into
  4452.      the slot. For example, if a :before method stores a value in the slot, the
  4453.      :initform form will not be used to supply a value for the slot.
  4454.  
  4455.    *  The rules mentioned in section 28.1.9.4 are obeyed.
  4456.  
  4457. The instance argument is the object to be initialized.
  4458.  
  4459. The slot-names argument specifies the slots that are to be initialized
  4460. according to their :initform forms if no initialization arguments apply. It is
  4461. supplied in one of three forms as follows:
  4462.  
  4463.    *  It can be a list of slot names, which specifies the set of those slot
  4464.      names.
  4465.  
  4466.    *  It can be nil, which specifies the empty set of slot names.
  4467.  
  4468.    *  It can be the symbol t, which specifies the set of all of the slots.
  4469.  
  4470. The initargs argument consists of alternating initialization argument names and
  4471. values.
  4472.  
  4473. The modified instance is returned as the result.
  4474.  
  4475. Initialization arguments are declared valid by using the :initarg option to
  4476. defclass, or by defining methods for shared-initialize. The keyword name of
  4477. each keyword parameter specifier in the lambda-list of any method defined on
  4478. shared-initialize is declared a valid initialization argument name for all
  4479. classes for which that method is applicable.
  4480.  
  4481. Implementations are permitted to optimize :initform forms that neither produce
  4482. nor depend on side effects by evaluating these forms and storing them into
  4483. slots before running any initialize-instance methods, rather than by handling
  4484. them in the primary initialize-instance method. (This optimization might be
  4485. implemented by having the allocate-instance method copy a prototype instance.)
  4486.  
  4487. Implementations are permitted to optimize default initial value forms for
  4488. initialization arguments associated with slots by not actually creating the
  4489. complete initialization argument list when the only method that would receive
  4490. the complete list is the method on standard-object. In this case, default
  4491. initial value forms can be treated like :initform forms. This optimization has
  4492. no visible effects other than a performance improvement.
  4493.  
  4494. See sections 28.1.9, 28.1.9.4, 28.1.9.2 as well as initialize-instance,
  4495. reinitialize-instance, update-instance-for-redefined-class,
  4496. update-instance-for-different-class, slot-boundp, and slot-makunbound.
  4497.  
  4498. [Function]
  4499. slot-boundp instance slot-name
  4500.  
  4501. The function slot-boundp tests whether a specific slot in an instance is bound.
  4502.  
  4503. The arguments are the instance and the name of the slot.
  4504.  
  4505. The function slot-boundp returns true or false.
  4506.  
  4507. This function allows for writing :after methods on initialize-instance in order
  4508. to initialize only those slots that have not already been bound.
  4509.  
  4510. If no slot of the given name exists in the instance, slot-missing is called as
  4511. follows:
  4512.  
  4513. (slot-missing (class-of instance)
  4514.               instance
  4515.               slot-name
  4516.               'slot-boundp)
  4517.  
  4518. The function slot-boundp is implemented using slot-boundp-using-class. See
  4519. slot-missing.
  4520.  
  4521. [Function]
  4522. slot-exists-p object slot-name
  4523.  
  4524. The function slot-exists-p tests whether the specified object has a slot of the
  4525. given name.
  4526.  
  4527. The object argument is any object. The slot-name argument is a symbol.
  4528.  
  4529. The function slot-exists-p returns true or false.
  4530.  
  4531. The function slot-exists-p is implemented using slot-exists-p-using-class.
  4532.  
  4533. [Function]
  4534. slot-makunbound instance slot-name
  4535.  
  4536. The function slot-makunbound restores a slot in an instance to the unbound
  4537. state.
  4538.  
  4539. The arguments to slot-makunbound are the instance and the name of the slot.
  4540.  
  4541. The instance is returned as the result.
  4542.  
  4543. If no slot of the given name exists in the instance, slot-missing is called as
  4544. follows:
  4545.  
  4546. (slot-missing (class-of instance)
  4547.               instance
  4548.               slot-name
  4549.               'slot-makunbound)
  4550.  
  4551. The function slot-makunbound is implemented using slot-makunbound-using-class.
  4552. See slot-missing.
  4553.  
  4554. [Generic function]
  4555. slot-missing class object slot-name operation &optional new-value
  4556.  
  4557. [Primary method]
  4558. slot-missing (class t) object slot-name operation &optional new-value
  4559.  
  4560. The generic function slot-missing is invoked when an attempt is made to access
  4561. a slot in an object whose metaclass is standard-class and the name of the slot
  4562. provided is not a name of a slot in that class. The default method signals an
  4563. error.
  4564.  
  4565. The generic function slot-missing is not intended to be called by programmers.
  4566. Programmers may write methods for it.
  4567.  
  4568. The required arguments to slot-missing are the class of the object that is
  4569. being accessed, the object, the slot name, and a symbol that indicates the
  4570. operation that caused slot-missing to be invoked. The optional argument to
  4571. slot-missing is used when the operation is attempting to set the value of the
  4572. slot.
  4573.  
  4574. If a method written for slot-missing returns values, these values get returned
  4575. as the values of the original function invocation.
  4576.  
  4577. The generic function slot-missing may be called during evaluation of
  4578. slot-value, (setf slot-value), slot-boundp, and slot-makunbound. For each of
  4579. these operations the corresponding symbol for the operation argument is
  4580. slot-value, setf, slot-boundp, and slot-makunbound, respectively.
  4581.  
  4582. The set of arguments (including the class of the instance) facilitates defining
  4583. methods on the metaclass for slot-missing.
  4584.  
  4585. [Generic function]
  4586. slot-unbound class instance slot-name
  4587.  
  4588. [Primary method]
  4589. slot-unbound (class t) instance slot-name
  4590.  
  4591. The generic function slot-unbound is called when an unbound slot is read in an
  4592. instance whose metaclass is standard-class. The default method signals an
  4593. error.
  4594.  
  4595. The generic function slot-unbound is not intended to be called by programmers.
  4596. Programmers may write methods for it. The function slot-unbound is called only
  4597. by the function slot-value-using-class and thus indirectly by slot-value.
  4598.  
  4599. The arguments to slot-unbound are the class of the instance whose slot was
  4600. accessed, the instance itself, and the name of the slot.
  4601.  
  4602. If a method written for slot-unbound returns values, these values get returned
  4603. as the values of the original function invocation.
  4604.  
  4605. An unbound slot may occur if no :initform form was specified for the slot and
  4606. the slot value has not been set, or if slot-makunbound has been called on the
  4607. slot.
  4608.  
  4609. See slot-makunbound.
  4610.  
  4611. [Function]
  4612. slot-value object slot-name
  4613.  
  4614. The function slot-value returns the value contained in the slot slot-name of
  4615. the given object. If there is no slot with that name, slot-missing is called.
  4616. If the slot is unbound, slot-unbound is called.
  4617.  
  4618. The macro setf can be used with slot-value to change the value of a slot.
  4619.  
  4620. The arguments are the object and the name of the given slot.
  4621.  
  4622. The result is the value contained in the given slot.
  4623.  
  4624. If an attempt is made to read a slot and no slot of the given name exists in
  4625. the instance, slot-missing is called as follows:
  4626.  
  4627. (slot-missing (class-of instance)
  4628.               instance
  4629.               slot-name
  4630.               'slot-value)
  4631.  
  4632. If an attempt is made to write a slot and no slot of the given name exists in
  4633. the instance, slot-missing is called as follows:
  4634.  
  4635. (slot-missing (class-of instance)
  4636.               instance
  4637.               slot-name
  4638.               'setf
  4639.               new-value)
  4640.  
  4641. The function slot-value is implemented using slot-value-using-class.
  4642.  
  4643. Implementations may optimize slot-value by compiling it in-line.
  4644.  
  4645. See slot-missing and slot-unbound.
  4646.  
  4647. [At this point the original CLOS report [5,7] contained a specification for
  4648. symbol-macrolet. This specification is omitted here. Instead, a description of
  4649. symbol-macrolet appears with those of related constructs in chapter 7.-GLS]
  4650.  
  4651. [Generic function]
  4652. update-instance-for-different-class previous current &rest initargs
  4653.  
  4654. [Primary method]
  4655.  
  4656. update-instance-for-different-class (previous standard-object)
  4657.          (current standard-object) &rest initargs
  4658.  
  4659. The generic function update-instance-for-different-class is not intended to be
  4660. called by programmers. Programmers may write methods for it. This function is
  4661. called only by the function change-class.
  4662.  
  4663. The system-supplied primary method on update-instance-for-different-class
  4664. checks the validity of initialization arguments and signals an error if an
  4665. initialization argument is supplied that is not declared valid. This method
  4666. then initializes slots with values according to the initialization arguments
  4667. and initializes the newly added slots with values according to their :initform
  4668. forms. It does this by calling the generic function shared-initialize with the
  4669. following arguments: the instance, a list of names of the newly added slots,
  4670. and the initialization arguments it received. Newly added slots are those local
  4671. slots for which no slot of the same name exists in the previous class.
  4672.  
  4673. Methods for update-instance-for-different-class can be defined to specify
  4674. actions to be taken when an instance is updated. If only :after methods for
  4675. update-instance-for-different-class are defined, they will be run after the
  4676. system-supplied primary method for initialization and therefore will not
  4677. interfere with the default behavior of update-instance-for-different-class.
  4678.  
  4679. The arguments to update-instance-for-different-class are computed by
  4680. change-class. When change-class is invoked on an instance, a copy of that
  4681. instance is made; change-class then destructively alters the original instance.
  4682. The first argument to update-instance-for-different-class, previous, is that
  4683. copy; it holds the old slot values temporarily. This argument has dynamic
  4684. extent within change-class; if it is referenced in any way once
  4685. update-instance-for-different-class returns, the results are undefined. The
  4686. second argument to update-instance-for-different-class, current, is the altered
  4687. original instance.
  4688.  
  4689. The intended use of previous is to extract old slot values by using slot-value
  4690. or with-slots or by invoking a reader generic function, or to run other methods
  4691. that were applicable to instances of the original class.
  4692.  
  4693. The initargs argument consists of alternating initialization argument names and
  4694. values.
  4695.  
  4696. The value returned by update-instance-for-different-class is ignored by
  4697. change-class.
  4698.  
  4699. See the example for the function change-class.
  4700.  
  4701. Initialization arguments are declared valid by using the :initarg option to
  4702. defclass, or by defining methods for update-instance-for-different-class or
  4703. shared-initialize. The keyword name of each keyword parameter specifier in the
  4704. lambda-list of any method defined on update-instance-for-different-class or
  4705. shared-initialize is declared a valid initialization argument name for all
  4706. classes for which that method is applicable.
  4707.  
  4708. Methods on update-instance-for-different-class can be defined to initialize
  4709. slots differently from change-class. The default behavior of change-class is
  4710. described in section 28.1.11.
  4711.  
  4712. See sections 28.1.11, 28.1.9.4, and 28.1.9.2 as well as change-class and
  4713. shared-initialize.
  4714.  
  4715. [Generic function]
  4716.  
  4717. update-instance-for-redefined-class instance
  4718.      added-slots discarded-slots property-list
  4719.      &rest initargs
  4720.  
  4721. [Primary method]
  4722.  
  4723. update-instance-for-redefined-class (instance standard-object)
  4724.      added-slots discarded-slots property-list
  4725.      &rest initargs
  4726.  
  4727. The generic function update-instance-for-redefined-class is not intended to be
  4728. called by programmers. Programmers may write methods for it. The generic
  4729. function update-instance-for-redefined-class is called by the mechanism
  4730. activated by make-instances-obsolete.
  4731.  
  4732. The system-supplied primary method on update-instance-for-different-class
  4733. checks the validity of initialization arguments and signals an error if an
  4734. initialization argument is supplied that is not declared valid. This method
  4735. then initializes slots with values according to the initialization arguments
  4736. and initializes the newly added slots with values according to their :initform
  4737. forms. It does this by calling the generic function shared-initialize with the
  4738. following arguments: the instance, a list of names of the newly added slots,
  4739. and the initialization arguments it received. Newly added slots are those local
  4740. slots for which no slot of the same name exists in the old version of the
  4741. class.
  4742.  
  4743. When make-instances-obsolete is invoked or when a class has been redefined and
  4744. an instance is being updated, a property list is created that captures the slot
  4745. names and values of all the discarded slots with values in the original
  4746. instance. The structure of the instance is transformed so that it conforms to
  4747. the current class definition. The arguments to
  4748. update-instance-for-redefined-class are this transformed instance, a list of
  4749. the names of the new slots added to the instance, a list of the names of the
  4750. old slots discarded from the instance, and the property list containing the
  4751. slot names and values for slots that were discarded and had values. Included in
  4752. this list of discarded slots are slots that were local in the old class and are
  4753. shared in the new class.
  4754.  
  4755. The initargs argument consists of alternating initialization argument names and
  4756. values.
  4757.  
  4758. The value returned by update-instance-for-redefined-class is ignored.
  4759.  
  4760. Initialization arguments are declared valid by using the :initarg option to
  4761. defclass or by defining methods for update-instance-for-redefined-class or
  4762. shared-initialize. The keyword name of each keyword parameter specifier in the
  4763. lambda-list of any method defined on update-instance-for-redefined-class or
  4764. shared-initialize is declared a valid initialization argument name for all
  4765. classes for which that method is applicable.
  4766.  
  4767. See sections 28.1.10, 28.1.9.4, and 28.1.9.2 as well as shared-initialize and
  4768. make-instances-obsolete.
  4769.  
  4770. (defclass position () ())
  4771.  
  4772. (defclass x-y-position (position)
  4773.   ((x :initform 0 :accessor position-x)
  4774.    (y :initform 0 :accessor position-y)))
  4775.  
  4776. ;;; It turns out polar coordinates are used more than Cartesian
  4777. ;;; coordinates, so the representation is altered and some new
  4778. ;;; accessor methods are added.
  4779.  
  4780. (defmethod update-instance-for-redefined-class :before
  4781.            ((pos x-y-position) added deleted plist &key)
  4782.   ;; Transform the x-y coordinates to polar coordinates
  4783.   ;; and store into the new slots.
  4784.   (let ((x (getf plist 'x))
  4785.         (y (getf plist 'y)))
  4786.     (setf (position-rho pos) (sqrt (+ (* x x) (* y y)))
  4787.           (position-theta pos) (atan y x))))
  4788.  
  4789. (defclass x-y-position (position)
  4790.     ((rho :initform 0 :accessor position-rho)
  4791.      (theta :initform 0 :accessor position-theta)))
  4792.  
  4793. ;;; All instances of the old x-y-position class will be updated
  4794. ;;; automatically.
  4795.  
  4796. ;;; The new representation has the look and feel of the old one.
  4797.  
  4798. (defmethod position-x ((pos x-y-position))
  4799.    (with-slots (rho theta) pos (* rho (cos theta))))
  4800.  
  4801. (defmethod (setf position-x) (new-x (pos x-y-position))
  4802.    (with-slots (rho theta) pos
  4803.      (let ((y (position-y pos)))
  4804.        (setq rho (sqrt (+ (* new-x new-x) (* y y)))
  4805.              theta (atan y new-x))
  4806.        new-x)))
  4807.  
  4808. (defmethod position-y ((pos x-y-position))
  4809.    (with-slots (rho theta) pos (* rho (sin theta))))
  4810.  
  4811. (defmethod (setf position-y) (new-y (pos x-y-position))
  4812.    (with-slots (rho theta) pos
  4813.      (let ((x (position-x pos)))
  4814.        (setq rho (sqrt (+ (* x x) (* new-y new-y)))
  4815.              theta (atan new-y x))
  4816.        new-y)))
  4817.  
  4818. [Macro]
  4819.  
  4820. with-accessors ({slot-entry}*) instance-form
  4821.                {declaration}* {form}*
  4822.  
  4823. The macro with-accessors creates a lexical environment in which specified slots
  4824. are lexically available through their accessors as if they were variables. The
  4825. macro with-accessors invokes the appropriate accessors to access the specified
  4826. slots. Both setf and setq can be used to set the value of the slot.
  4827.  
  4828. The result returned is that obtained by executing the forms specified by the
  4829. body argument.
  4830.  
  4831. Example:
  4832.  
  4833. (with-accessors ((x position-x) (y position-y)) p1
  4834.   (setq x y))
  4835.  
  4836. A with-accessors expression of the form
  4837.  
  4838. (with-accessors (   ...   ) instance
  4839.      ...   )
  4840.      ...   )
  4841.  
  4842. expands into the equivalent of
  4843.  
  4844. (let ((in instance))
  4845.   (symbol-macrolet ((   (   in))
  4846.                     ...
  4847.                     (   (   in)))
  4848.        ...   )
  4849.        ...   )
  4850.  
  4851. [X3J13 voted in March 1989 (SYMBOL-MACROLET-SEMANTICS)   to modify the
  4852. definition of symbol-macrolet substantially and also voted
  4853. (SYMBOL-MACROLET-DECLARE)   to allow declarations before the body of
  4854. symbol-macrolet but with peculiar treatment of special and type declarations.
  4855. The syntactic changes are reflected in this definition of with-accessors.-GLS]
  4856.  
  4857. See with-slots and symbol-macrolet.
  4858.  
  4859. [Special Form]
  4860.  
  4861. with-added-methods (function-name lambda-list
  4862.                    [[?option | {method-description}*]])
  4863.                    {form}*
  4864.  
  4865. The with-added-methods special form produces new generic functions and
  4866. establishes new lexical function definition bindings. Each generic function is
  4867. created by adding the set of methods specified by its method definitions to a
  4868. copy of the lexically visible generic function of the same name and its
  4869. methods. If such a generic function does not already exist, a new generic
  4870. function is created; this generic function has lexical scope.
  4871.  
  4872. The special form with-added-methods is used to define functions whose names are
  4873. meaningful only locally and to execute a series of forms with these function
  4874. definition bindings.
  4875.  
  4876. The names of functions defined by with-added-methods have lexical scope; they
  4877. retain their local definitions only within the body of the with-added-methods
  4878. construct. Any references within the body of the with-added-methods construct
  4879. to functions whose names are the same as those defined within the
  4880. with-added-methods form are thus references to the local functions instead of
  4881. to any global functions of the same names. The scope of these generic function
  4882. definition bindings includes the method bodies themselves as well as the body
  4883. of the with-added-methods construct.
  4884.  
  4885. The function-name, option, method-qualifier, and specialized-lambda-list
  4886. arguments are the same as for defgeneric.
  4887.  
  4888. The body of each method is enclosed in an implicit block. If function-name is a
  4889. symbol, this block bears the same name as the generic function. If
  4890. function-name is a list of the form (setf symbol), the name of the block is
  4891. symbol.
  4892.  
  4893. The result returned by with-added-methods is the value or values of the last
  4894. form executed. If no forms are specified, with-added-methods returns nil.
  4895.  
  4896. If a generic function with the given name already exists, the lambda-list
  4897. specified in the with-added-methods form must be congruent with the
  4898. lambda-lists of all existing methods on that function as well as with the
  4899. lambda-lists of all methods defined by the with-added-methods form; otherwise
  4900. an error is signaled.
  4901.  
  4902. If function-name specifies an existing generic function that has a different
  4903. value for any of the following option arguments, the copy of that generic
  4904. function is modified to have the new value: :argument-precedence-order,
  4905. declare, :documentation, :generic-function-class, :method-combination.
  4906.  
  4907. If function-name specifies an existing generic function that has a different
  4908. value for the :method-class option argument, that value is changed in the copy
  4909. of that generic function, but any methods copied from the existing generic
  4910. function are not changed.
  4911.  
  4912. If a function of the given name already exists, that function is copied into
  4913. the default method for a generic function of the given name. Note that this
  4914. behavior differs from that of defgeneric.
  4915.  
  4916. If a macro or special form of the given name already exists, an error is
  4917. signaled.
  4918.  
  4919. If there is no existing generic function, the option arguments have the same
  4920. default values as the option arguments to defgeneric.
  4921.  
  4922. See generic-labels, generic-flet, defmethod, defgeneric, and
  4923. ensure-generic-function.
  4924.  
  4925. [Macro]
  4926.  
  4927. with-slots ({slot-entry}*) instance-form
  4928.       {declaration}* {form}*
  4929.  
  4930. slot-entry ::= slot-name | (variable-name slot-name)
  4931.  
  4932. The macro with-slots creates a lexical context for referring to specified slots
  4933. as though they were variables. Within such a context the value of the slot can
  4934. be specified by using its slot name, as if it were a lexically bound variable.
  4935. Both setf and setq can be used to set the value of the slot.
  4936.  
  4937. The macro with-slots translates an appearance of the slot name as a variable
  4938. into a call to slot-value.
  4939.  
  4940. The result returned is that obtained by executing the forms specified by the
  4941. body argument.
  4942.  
  4943. Example:
  4944.  
  4945. (with-slots (x y) position-1
  4946.   (sqrt (+ (* x x) (* y y))))
  4947.  
  4948. (with-slots ((x1 x) (y1 y)) position-1
  4949.   (with-slots ((x2 x) (y2 y)) position-2
  4950.     (psetf x1 x2
  4951.            y1 y2))))
  4952.  
  4953. (with-slots (x y) position
  4954.   (setq x (1+ x)
  4955.         y (1+ y)))
  4956.  
  4957. A with-slots expression of the form:
  4958.  
  4959. (with-slots (   ...   ) instance
  4960.      ...   )
  4961.      ...   )
  4962.  
  4963. expands into the equivalent of
  4964.  
  4965. (let ((in instance))
  4966.   (symbol-macrolet (   ...   )
  4967.        ...   )
  4968.        ...   )
  4969.  
  4970. where    is
  4971.  
  4972. (   (slot-value in '  ))
  4973.  
  4974. if    is a symbol and is
  4975.  
  4976. (   (slot-value in '  ))
  4977.  
  4978. if    is of the form (     ).
  4979.  
  4980. [X3J13 voted in March 1989 (SYMBOL-MACROLET-SEMANTICS)   to modify the
  4981. definition of symbol-macrolet substantially and also voted
  4982. (SYMBOL-MACROLET-DECLARE)   to allow declarations before the body of
  4983. symbol-macrolet but with peculiar treatment of special and type declarations.
  4984. The syntactic changes are reflected in this definition of with-slots.-GLS]
  4985.  
  4986. See with-accessors and symbol-macrolet.
  4987. [change_end]
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  
  4993.  
  4994.  
  4995.  
  4996.  
  4997.  
  4998.  
  4999.  
  5000.  
  5001.